Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. // y"+1/x *y'+0.5y=0.5*(x*x)-ln(x)+4
  9. double a=1;
  10. double b=2;
  11. double n = 5;
  12. double h=(b-a)/n;
  13.  
  14. double c1=1, c2=-1.2, c=0;
  15. double d1=2, d2=-2.5, d=-4;
  16.  
  17. double Arr[3][30];
  18. int i=0;
  19. for(double x=a; x<b; x+=h)
  20. {
  21. Arr[0][i]=1/x;
  22. Arr[1][i]=0.5;
  23. Arr[2][i]=0.5*(x*x)-log(x)+4;
  24. //cout << Arr[2][i]*(h*h)<<" "<< x<< endl;
  25. i++;
  26. }
  27.  
  28. double W[30][30];
  29.  
  30. for(int i=0; i<n; i++)
  31. for(int j=0; j<n; j++)
  32. {
  33. W[i][j]=0;
  34. }
  35.  
  36. for(int i=0; i<n; i++)
  37. {
  38. int k=0;
  39. for(int j=0; j<n; j++)
  40. {
  41. if (k<3)
  42. {
  43. if(k==0) W[i][j+i]=1-Arr[0][i]*h+Arr[1][i]*(h*h);
  44. else if (k==1) W[i][j+i]=-2+Arr[0][i]*h;
  45. else W[i][j+i]= 1;
  46. }
  47. k++;
  48.  
  49. }
  50. k=0;
  51. }
  52.  
  53. for(int i=0; i<n; i++)
  54. {
  55. for(int j=0; j<n; j++)
  56. {
  57. cout << W[i][j] << " ";
  58. }
  59. cout << " = " << Arr[2][i]*(h*h) << endl;
  60. }
  61.  
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement