Advertisement
frustration

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

Mar 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. /* составить программу решения ур-й методом итераций по ф-ам xn=F1(xn-1,yn-1)
  2. yn=F2(xn-1,yn-1),n=1.2...
  3.  
  4. начальные значения х0 и у0 заданы
  5.  
  6.  
  7. вычисления для системы y*sin(x)-x=0
  8.                        x*sin(y)-x=0
  9.  
  10. правило остановки счета:abs(x1 - x0) + abs(y1-y0) <= eps, eps=1e-4
  11. */
  12.  
  13. #include <iostream>
  14. #include <conio.h>
  15. #include <cmath>
  16. #include <stdio.h>
  17.  
  18. using namespace std;
  19.  
  20. float function1(float x, float y){
  21.     return x*sin(y);
  22. }
  23. float function2(float x, float y){
  24.     return x / sin(x);
  25. }
  26.  
  27.  
  28. void iterative_relation(float x, float y){
  29.     float eps = 1e-4;
  30.     float x1 = function1(x,y);
  31.     float y1 = function2(x,y);
  32.     while (abs(x1 - x) + abs(y1 - y) > eps){
  33.  
  34.         x = x1;
  35.         y = y1;
  36.         x1 = function1(x, y);
  37.         y1 = function2(x, y);
  38.  
  39.     }
  40.  
  41.     printf_s("solution to equation x= %6.5f, y= %6.5f", x1, y1);
  42.  
  43. }
  44.  
  45. int main(){
  46.     float x0, y0;
  47.     cout << "enter initial values of function inputs:" << endl;
  48.     cout << "x0= ";
  49.     cin >> x0;
  50.     cout << "y0= ";
  51.     cin>> y0;
  52.  
  53.     iterative_relation(x0, y0);
  54.  
  55.     _getch();
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement