Advertisement
Guest User

auesifhneawiuhfsnuAFEUAIWEHFUIOASHFDUIS

a guest
May 30th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<fstream>
  4. using namespace std;
  5. const double deltat=0.0001;
  6. const double h=0.01;
  7. const int K=2.0/deltat;
  8. const int N=18.0/h;
  9. const double lambda=deltat/(h*h);
  10. ofstream plik("Rozwiazanie.txt");
  11. void ThomasEliminacja1(double l[], double d[], double u[], double eta[], const int N)
  12. {
  13. eta[0]=d[0];
  14. for (int i=1; i<N; i++)
  15. {
  16. eta[i]=d[i]-(l[i-1]*u[i-1]/eta[i-1]);
  17. }
  18. }
  19.  
  20. void ThomasEliminacja2(double l[], double u[], double eta[], double b[], double r[], double x[], const int N)
  21. {
  22. r[0]=b[0];
  23. for (int i=1; i<N; i++)
  24. r[i]=b[i]-(l[i-1]*r[i-1]/eta[i-1]);
  25.  
  26. x[N-1]=(1.0/eta[N-1])*r[N-1];
  27. for (int i=N-2; i>=0; i--)
  28. x[i]=(r[i]-u[i]*x[i+1])/eta[i];
  29. }
  30.  
  31. void Laasonen()
  32. {
  33. double *l=new double[K];
  34. double *d=new double[K+1];
  35. double *upp=new double[K];
  36. double *eta=new double[K+1];
  37. double *b=new double[K+1];
  38. double *r=new double[K+1];
  39. // double **U=new double[K+1][N+1];
  40. double **U=new double*[K+1];
  41. for (int i=0; i<K+1; i++)
  42. U[i]=new double[N+1];
  43. for (int i=0; i<K-1; i++)
  44. l[i]=lambda;
  45. l[N-1]=0.0;
  46.  
  47. d[0]=1.0;
  48. for (int i=1; i<K; i++)
  49. d[i]=-(1.0+2.0*lambda);
  50. d[K]=1.0;
  51.  
  52. upp[0]=0.0;
  53. for (int i=1; i<K; i++)
  54. upp[i]=lambda;
  55. //zastepujemy przedzial nieskonczony przedzialem [-9, 9]
  56. for (int n=0; n<=N; n++)
  57. if (n<N/2)
  58. U[0][n]=1.0;
  59. else
  60. U[0][n]=0.0;
  61.  
  62. for (int k=0; k<=K; k++)
  63. U[k][0]=1.0;
  64. U[K][N]=0.0;
  65.  
  66. b[0]=-1.0;
  67. b[K]=0.0;
  68. ThomasEliminacja1(l, d, upp, eta, K);
  69. for (int k=1; k<=K; k++)
  70. {
  71.  
  72. for (int n=1; n<N; n++)
  73. b[n]=-U[k][n];
  74. ThomasEliminacja2(l, upp, eta, b, r, U[k], K);
  75. }
  76.  
  77. for (int k=0; k<=K; k++)
  78. {
  79. for (int n=0; n<=N; n++)
  80. plik<<U[k][n]<<" ";
  81. plik<<endl;
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. }
  92. int main()
  93. {
  94. Laasonen();
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement