Advertisement
frustration

DONE. итерационная ф-ла. вариант 1. функция

Mar 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. /*
  2. составить программу вычисления корня у-я согласнo итерационной ф-ле xk+1=xk-f(xk)/f'(xk), к =1,2,3.. с точностью до eps=1Е-3
  3. правило остановки счета:(abs(x1 - x0) <= eps); ур -е :cos(x0) + 2 * x0 - 1=0. предварительно произвести уточнение корней на отрезке [-1,2]
  4. */
  5. #include <iostream>
  6. #include <conio.h>
  7. #include <cmath>
  8. #include <iomanip>
  9. #include <stdio.h>
  10.  
  11. using namespace std;
  12. float function(float x0){
  13.     return  x0 - (cos(x0-0.5) + 2 * x0 - 1) / (-sin(x0-0.5) + 2);
  14. }
  15.  
  16. float iterative_relation(float x0){
  17.     float eps = 1e-4;
  18.     float x1 = function(x0);
  19.     while (abs(x1 - x0) > eps){
  20.  
  21.         x0 = x1;
  22.         x1 = function(x0);
  23.     }
  24.     return x1;
  25. }
  26.  
  27. int main(){
  28.  
  29.     float  x0;
  30.     cin >> x0;
  31.     printf_s("x1 = %6.5f", iterative_relation(x0));
  32.  
  33.     _getch();
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement