Advertisement
timursaet

Ellira

Oct 24th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <cmath>
  4. #include <locale>
  5.  
  6. using namespace std;
  7.  
  8. double F(double x, double y) {
  9.     return ((-0.5)*(y / x)) + x * x;
  10. }
  11.  
  12. double tocnoe_rechenie(double x) {
  13.     return ((2.0/7)*x*x*x) + ((5.0/7) / sqrt(x));
  14. }
  15.  
  16. int main() {
  17.     setlocale(LC_ALL, "Russian");
  18.     double a = 1, b = 2, h = 0.1;
  19.     double n = (b - a) / h;
  20.     double X[12], Y[12], Y1[12], raz[12];
  21.     X[0] = a, Y[0]=1;
  22.  
  23.     for (int i = 1; i < n+1; i++) {
  24.         X[i] = a + i * h;
  25.         Y[i] = Y[i - 1] + h * F(X[i - 1], Y[i - 1]);
  26.         //Y[1] = 1;
  27.     }
  28.  
  29.     for (int i = 1; i < n+1; i++) {
  30.         cout << "X[" << i << "]=" << X[i] << " "<<"\n";
  31.     }
  32.  
  33.     cout << endl;
  34.  
  35.     for (int i = 1; i < n+1; i++) {
  36.         cout << "Y[" << i << "]=" << Y[i] << " "<<"\n";
  37.     }
  38.  
  39.     cout << "\nТочное решение\n" << endl;
  40.  
  41.     for (int i = 1; i < n+1; i++) {
  42.         Y1[i] = tocnoe_rechenie(X[i]);
  43.         cout << "Y1[" << i << "]=" << Y1[i] << " " << "\n";
  44.     }
  45.  
  46.     cout << "\nПогрешность\n" << endl;
  47.  
  48.     for (int i = 1; i < n+1; i++) {
  49.         raz[i] = abs(Y1[i] - Y[i]);
  50.         cout << raz[i] << "\n";
  51.     }
  52.  
  53.     system("pause");
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement