. [a, b] (.4.4).
.4.4. .
f(a) f(b). f(a)*f(b)>0, . f(a)*f(b)<0, .. [a, b] f(x) , . . a y1 = f(a). x b, y2 = f(x). , f(a)*f(x)>0, [x, b], [a, x]. , , , = b = x. , [a, b], . , [a, b] . x = (a+b)/2.
4.4. e = 0.01 , [1,3].
#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
int main()
{ int n = 0;
float x, a = 1, b = 3, y1, y2, eps = 0.001, e, r, l;
l = a; r = b;
y1 = a*a*a 2*a*a 3;
y2 = b*b*b 2*b*b 3;
if (y1*y2>0) { cout << " " <<endl;
getch();
exit(1);
}
do { ++n;
x = (a+b)/2;
y1 = a*a*a 2*a*a 3;
y2 = x*x*x 2*x*x 3;
if (y1*y2>0) a = x;
else b = x;
} while ((b a)>eps);
x = (a + b)/2;
cout << " "<< l << ", " << r << " " << x << " " << n <<"";
cout << endl;
return 0; }
1
Eps.
1, 16 | |
2, 17 | |
3, 18 | |
4, 19 | |
5, 20 | |
6, 21 | |
7, 22 | |
8, 23 | |
9, 24 | |
10, 25 | |
11, 26 | |
12, 27 | |
13, 28 | |
14, 29 | |
15, 30 |
2
1, 16 | x + ln(x + 0.5) 0.5 = 0 [0, 2]. . . |
2, 17 | 2x3 + 4x 1 = 0 [0, 0.5]. . . |
3, 18 | 1/x = sin x [0.1, 2]. . . |
4, 19 | . 0.001. . |
5, 20 | x4 + 2x3 x 1 = 0 [0, 1]. 0.00015. . |
6, 21 | x3 + 12x 2 = 0 [0.1, 1]. 0.00015. . |
7, 22 | . 0.001. . |
8, 23 | x5 x 0.2 = 0 [0.9,1.1]. 0.0001. . |
9, 24 | 5x + 8lnx 1 = 0 [0.5, 1]. 0.0015. . |
10, 25 | 0.001. . |
11, 26 | x3 2x2 + x 3 = 0 [2.1, 2.2]. 0.001. . |
12, 27 | x3 + x2 3 = 0 [0.5, 3]. 0.00001. . |
13, 28 | . 0.001. . |
14, 29 | . 0.001. . |
15, 30 | . 0.001. . |
|
|