Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- int N;
- double x0,xn,h;
- double g(int i)
- {
- return x0+i*h;
- }
- double p(int i)
- {
- return 0;
- }
- double q(int i)
- {
- return tan((x0+i*h)-1);
- }
- double A(int i)
- {
- return 1+(h/2)*p(i);
- }
- double B(int i)
- {
- return -2+pow(h,2)*q(i);
- }
- double C(int i)
- {
- return 1-(h/2)*p(i);
- }
- double l(int i)
- {
- if (i==0) return 0;
- else return -A(i)/(B(i)+C(i)*l(i-1));
- }
- double k(int i)
- {
- if (i==0) return x0;
- else return (pow(h,2)*g(i)-C(i)*k(i-1))/(B(i)+C(i)*l(i-1));
- }
- double u(int i)
- {
- if (i==N){cout<<"\n"<<xn; return xn;}
- else{double tmp=l(i)*u(i+1)+k(i); cout<<"\n"<<tmp; return tmp ;}
- }
- int main ()
- {
- cout << "N: ";
- cin >>N;
- cout << "\n a:";
- cin >> x0;
- cout<< "\n b:";
- cin>>xn;
- h=(xn-x0)/N;
- cout <<endl<< u(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement