include Windows include math include stdio include process include GL

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#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;
}