Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. int N;
  5. double x0,xn,h;
  6. double g(int i)
  7. {
  8.     return x0+i*h;
  9. }
  10. double p(int i)
  11. {
  12.     return 0;
  13. }
  14. double q(int i)
  15. {
  16.     return tan((x0+i*h)-1);
  17. }
  18. double A(int i)
  19. {
  20.     return 1+(h/2)*p(i);
  21. }
  22. double B(int i)
  23. {
  24.     return -2+pow(h,2)*q(i);
  25. }
  26. double C(int i)
  27. {
  28.     return 1-(h/2)*p(i);
  29. }
  30. double l(int i)
  31. {
  32.     if (i==0) return 0;
  33.     else return -A(i)/(B(i)+C(i)*l(i-1));
  34. }
  35. double k(int i)
  36. {
  37.     if (i==0) return x0;
  38.     else return (pow(h,2)*g(i)-C(i)*k(i-1))/(B(i)+C(i)*l(i-1));
  39. }
  40. double u(int i)
  41. {
  42.     if (i==N){cout<<"\n"<<xn; return xn;}
  43.     else{double tmp=l(i)*u(i+1)+k(i); cout<<"\n"<<tmp; return tmp  ;}
  44. }
  45.  
  46.  
  47. int main ()
  48. {
  49.  
  50.     cout << "N: ";
  51.     cin >>N;
  52.     cout << "\n a:";
  53.     cin >> x0;
  54.     cout<< "\n b:";
  55.     cin>>xn;
  56.     h=(xn-x0)/N;
  57.     cout <<endl<< u(0);
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement