Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int main()
- {
- // y"+1/x *y'+0.5y=0.5*(x*x)-ln(x)+4
- double a=1;
- double b=2;
- double n = 5;
- double h=(b-a)/n;
- double c1=1, c2=-1.2, c=0;
- double d1=2, d2=-2.5, d=-4;
- double Arr[3][30];
- int i=0;
- for(double x=a; x<b; x+=h)
- {
- Arr[0][i]=1/x;
- Arr[1][i]=0.5;
- Arr[2][i]=0.5*(x*x)-log(x)+4;
- //cout << Arr[2][i]*(h*h)<<" "<< x<< endl;
- i++;
- }
- double W[30][30];
- for(int i=0; i<n; i++)
- for(int j=0; j<n; j++)
- {
- W[i][j]=0;
- }
- for(int i=0; i<n; i++)
- {
- int k=0;
- for(int j=0; j<n; j++)
- {
- if (k<3)
- {
- if(k==0) W[i][j+i]=1-Arr[0][i]*h+Arr[1][i]*(h*h);
- else if (k==1) W[i][j+i]=-2+Arr[0][i]*h;
- else W[i][j+i]= 1;
- }
- k++;
- }
- k=0;
- }
- for(int i=0; i<n; i++)
- {
- for(int j=0; j<n; j++)
- {
- cout << W[i][j] << " ";
- }
- cout << " = " << Arr[2][i]*(h*h) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement