Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- double f(double x, int k)
- {
- return (x - k * cos(x));
- }
- double pr(double x, int k)
- {
- return (1 + k * sin(x));
- }
- double pd(double a, double b, double eps, int k)
- {
- double c, x;
- int i;
- i = 0;
- while (abs(a - b) > eps)
- {
- c = (a + b) / 2;
- if ((f(a, k) * f(c, k)) < 0)
- {
- b = c;
- }
- else
- {
- a = c;
- }
- i++;
- }
- x = (a + b) / 2;
- cout << i << " iterrations" << endl;
- return x;
- }
- double newton(double a, double eps, int k)
- {
- double x1, xn;
- int i;
- i = 0;
- x1 = a;
- xn = x1 - f(x1, k) / pr(x1, k);
- while (abs(xn - x1) > eps)
- {
- x1 = xn;
- xn = x1 - f(x1, k) / pr(x1, k);
- i++;
- }
- cout << i << " iterrations" << endl;
- return xn;
- }
- double iterration(double a, double eps, int k)
- {
- double x1, xn;
- int i;
- i = 0;
- x1 = a;
- xn = k * cos(x1);
- while (abs(xn - x1) > eps)
- {
- x1 = xn;
- xn = k * cos(x1);
- i++;
- if (i > 100000)
- break;
- }
- cout << i << " iterrations" << endl;
- return xn;
- }
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- #include "прототипы.h"
- using namespace std;
- int main(){
- setlocale(LC_ALL, "rus");
- double a, b, kor;
- cin >> a;
- cin >> b;
- cout << endl;
- cout << "x-cos(x)"<< endl;
- kor = pd(a, b, 0.000001, 1);
- cout <<" метод половинное деление " << kor << endl;
- cout << endl;
- kor = newton(a, 0.000001, 1);
- cout <<"метод Ньютона "<< kor << endl;
- cout << endl;
- kor = iterration(a, 0.000001, 1);
- cout <<"метод итерации " <<kor << endl;
- cout << endl;
- cout << "x-cos(x)" << endl;
- kor = pd(a, b, 0.00000001, 1);
- cout << fixed << setprecision(8)<< "метод половинное деление " << kor << endl;
- cout << endl;
- kor = newton(a, 0.00000001, 1);
- cout << fixed << setprecision(8) << "метод Ньютона " << kor << endl;
- cout << endl;
- kor = iterration(a, 0.00000001, 1);
- cout <<fixed << setprecision(8)<< "метод итерации " << kor << endl;
- cout << endl;
- cout << "x-10cos(x)" << endl;
- kor = pd(a, b, 0.000001, 10);
- cout << "метод половинное деление " << kor << endl;
- cout << endl;
- kor = newton(a, 0.000001, 10);
- cout << "метод Ньютона " << kor << endl;
- cout << endl;
- kor = iterration(a, 0.000001, 10);
- cout << "метод итерации " << kor << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement