#include <Windows.h>
#include <math.h>
#include <stdio.h>
#include <process.h>
#include <GL\glut.h>
#include <GL\GL.h>
using namespace std;
double x(double x, double y)
{
return (1 + y*y/3);
}
double y(double x, double y)
{
return (-1 - 1/(x+1));
}
void display()
{
//координатная плоскость
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex2f(-550, 0);
glVertex2f(550, 0);
glEnd();
glBegin(GL_LINES);
glVertex2f(0, 150);
glVertex2f(0, -150);
glEnd();
glPointSize(2.0);
for (int i = -550; i < 550; i = i + 10)
{
if (i == 0)
{
glPointSize(4.0);
glBegin(GL_POINTS);
glColor3f(1.0, 1.0, 1.0);
glVertex2d(i, 0);
glEnd();
}
else
{
glPointSize(2.0);
glBegin(GL_POINTS);
glColor3f(1.0, 1.0, 1.0);
glVertex2d(i, 0);
glEnd();
}
}
for (int i = -150; i < 150; i = i + 10)
{
if (i == 0)
{
glPointSize(4.0);
glBegin(GL_POINTS);
glColor3f(1.0, 1.0, 1.0);
glVertex2d(0, i);
glEnd();
}
else
{
glPointSize(2.0);
glBegin(GL_POINTS);
glColor3f(1.0, 1.0, 1.0);
glVertex2d(0, i);
glEnd();
}
}
double eps = 0.001;
double curr[2] { 1.5, 0};
int n = 2;
double norm = 0;
double next[2];
int count = 1;
int t = 10;
printf("x - (y^2)/3 = 1\ny + 1/(x+1) = -1\n");
do
{
next[0] = x(curr[0], curr[1]);
next[1] = y(next[0], curr[1]);
norm = 0;
for (int i = 0; i < n; ++i)
{
norm = max(abs(next[i] - curr[i]), norm);
}
count++;
for (int k = 0; k < n; k++)
curr[k] = next[k];
printf("%.3f, %.3f\n", curr[0], curr[1]);
glBegin(GL_POINTS);
glColor3f(1.0, 1.0, 1.0);
glVertex2d(curr[1]*t, count*t);
glEnd();
} while (norm > eps);
printf("intertions %d", count);
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600 * 2, 165 * 2);
glutInitWindowPosition(0, 0);
glutCreateWindow("Sin");
glClearColor(1.0, 1.0, 1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-600.0, 600.0, -200.0, 200.0, -1.0, 1.0);
glutDisplayFunc(display);
glutMainLoop();
system("pause");
return 0;
}