ModestGenius

cheese1

Feb 28th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. // ConsoleApplication10.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "iostream"
  6. #include "math.h"
  7. #include <iomanip>
  8. using namespace std;
  9.  
  10. double P(double x)
  11. {
  12.     return x;
  13. }
  14.  
  15. double Q(double x)
  16. {
  17.     return 1;
  18. }
  19.  
  20. double F(double x)
  21. {
  22.     return (double) 0;
  23. }
  24.  
  25.  
  26. int _tmain(int argc, _TCHAR* argv[])
  27. {
  28.     double a=0,b=1,h;
  29.     int N=5;
  30.     /*cout<<"Vvedite a: \n";
  31.     cin>>a;
  32.     cout<<"Vvedite b: \n";
  33.     cin>>b;
  34.     cout<<"Vvedite N: \n";
  35.     cin>>N;*/
  36.  
  37.  
  38.     h = (double) (b-a)/N;
  39.     double *x = new double[N];
  40.  
  41.  
  42.     double **y = new double*[N];
  43.     for(int i=0;i<N;i++)
  44.         y[i]=new double [N+2];
  45.  
  46.  
  47.  
  48.     for (int i = 0; i < N; i++)
  49.     {
  50.         x[i]=a+i*h;
  51.     }
  52.     for (int i=0;i<N;i++)
  53.         for(int j=0;j<N+2;j++)
  54.             y[i][j]=0;
  55.     for(int i=1;i<N-1;i++)
  56.         y[i][N+1]=F(x[i]);
  57.  
  58.     y[0][N+1]=1.0;
  59.     y[N-1][N+1]=0.2233;
  60.  
  61.     y[0][0]=1;
  62.     y[N-1][N]=1;
  63.  
  64.     int l = 1;
  65.     while(l<N-1)
  66.     {
  67.         y[l][l] = 1 - (P(x[l+1])*h)/2;
  68.         y[l][l+1]=-2 + h*h*Q(x[l+1]);
  69.         y[l][l+2]=1 + (P(x[l+1])*h)/2;
  70.         l++;
  71.     }
  72.     for (int i=0;i<N;i++)
  73.     {
  74.         for(int k=0;k<=N+1;k++)
  75.         {
  76.              cout << left << setw(8) <<y[i][k];
  77.         }
  78.         cout<<endl;
  79.     }
  80.  
  81.  
  82.  
  83.  
  84.     system("pause");
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment