Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <math.h>
- using namespace std;
- double xx0, xx1; // промежуток в ответе шагового метода
- double a = 0, b = 1, h = 0.1, e = 0.001; // исходные данные
- double function(double x)
- {
- return acos(x) - sqrt(1 - 0.3 * pow(x, 3)); // Исходная функция
- }
- double derivative(double x)
- {
- return (-1 / sqrt(1 - pow(x, 2))) + ((0.45 * pow(x, 2)) / sqrt(1 - 0.3 * pow(x, 3))); // Производная исходной функции
- }
- double S(double x)
- {
- return x - 0.005 * function(x);
- }
- void step_method() // Шаговый метод.
- {
- double x0 = a, x1 = x0 + h;
- while (x1 <= b)
- {
- x1 = x0 + h;
- if (function(x0) * function(x1) < 0)
- {
- cout << "Step method:\n";
- cout << "x on int. [" << x0 << "," << x1 << "]\n" << endl;
- xx0 = x0;
- xx1 = x1;
- }
- x0 = x1;
- }
- }
- void bisection_method() // Метод половинного деления.
- {
- double x = xx0;
- a = xx0;
- b = xx1;
- while (fabs(function(x)) > e)
- {
- x = (a + b) / 2;
- if (function(a) * function(x) < 0)
- b = x;
- else a = x;
- }
- cout << "Bisection method:\nx= " << x << "\n" << endl;
- }
- void newton_method() // Метод Ньютона.
- {
- double x2 = xx0;
- while (fabs(function(x2)) > e)
- {
- x2 = x2 - function(x2) / derivative(x2);
- }
- cout << "Newton's method:\nx= " << x2 << "\n" << endl;
- }
- void fixed_point_iteration() // Метод простой итерации.
- {
- double x3 = xx0;
- while (fabs(function(x3)) > e)
- {
- x3 = S(x3);
- }
- cout << "Fixed-point iteration method:\nx= " << x3 << "\n" << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "");
- step_method();
- bisection_method();
- newton_method();
- fixed_point_iteration();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement