Advertisement
SomeBody_Aplle

Untitled

Jan 18th, 2022
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. using namespace std;
  5.  
  6. double F(double x, double y) {
  7.     return 3 * sin(2 * y) + x;
  8. }
  9.  
  10.  
  11. int main(int argc, char** argv)
  12. {
  13.     double a = 0; double b = 1; double h = 0.1;
  14.     double n = ((b - a) / h) + 1;
  15.     unique_ptr<double[]> X(new double[(int)n]);
  16.     unique_ptr<double[]> Y(new double[(int)n]);
  17.     X[0] = a; Y[0] = 2;
  18.  
  19.  
  20.     for (int i = 1; i <= n - 1; i++) {
  21.         X[i] = a + i * h;
  22.         Y[i] = Y[i - 1] + h * F(X[i - 1], Y[i - 1]);
  23.     }
  24.  
  25.  
  26.     for (int i = 0; i <= n - 1; i++) {
  27.         cout << "X[" << i << "]=" << X[i] << " ";
  28.     }
  29.     cout << std::endl;
  30.     for (int i = 0; i <= n - 1; i++) {
  31.         cout << "Y[" << i << "]=" << Y[i] << " ";
  32.     }
  33.  
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement