Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <math.h>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. void main(void);
  9.  
  10. float f(float x, float t);
  11.  
  12. float mu_1(float t);
  13.  
  14. float mu_2(float t);
  15.  
  16. float phi(float x);
  17.  
  18. // – //
  19.  
  20. void main(void)
  21.  
  22. {
  23. setlocale(0, "RUS");
  24.  
  25. float a[256][256];
  26. float b[256][256];
  27. float u[256][256];
  28. float T = 0.05;
  29. float l = 3.14;
  30. float h = 0.1;
  31. float tau = 0.01;
  32. int n, i, j, k;
  33. float s = pow(h, 2) / tau;
  34. n = ceil(l / h);
  35.  
  36. for (i = 0; i <= 119; i++)
  37. {
  38. for (j = 1; j <= 119; j++)
  39. {
  40. u[i][j] = 0;
  41. a[i][j] = 0;
  42. b[i][j] = 0;
  43. }
  44. }
  45.  
  46. for (i = 0; i <= n; i++)
  47. {
  48. u[i][0] = phi(i * h);
  49. }
  50.  
  51. for (j = 0; j <= floor(T / tau); j++)
  52. {
  53. u[0][j] = mu_1(tau * j);
  54. u[n][j] = mu_2(tau * j);
  55. }
  56.  
  57. for (j = 0; j <= floor(T / tau); j++)
  58. {
  59.  
  60. a[1][j + 1] = 1 / (2 + s);
  61.  
  62. for (i = 2; i <= n - 1; i++)
  63. {
  64. a[i][j + 1] = 1 / (2 + s - a[i - 1][j + 1]);
  65. }
  66.  
  67. b[1][j + 1] = mu_1((j + 1) * tau) + s * u[1][j] + pow(h, 2) * f(h, (j + 1) * tau);
  68.  
  69. for (i = 2; i <= n - 1; i++)
  70. {
  71. b[i][j + 1] = a[i - 1][j + 1] + s * u[i][j] + pow(h, 2) * f(i * h, (j + 1) * tau);
  72. }
  73.  
  74. u[n][j + 1] = mu_2((j + 1) * tau);
  75.  
  76. for (k = 1; k <= n - 1; k++)
  77. {
  78. u[n - k][j + 1] = a[n - k][j + 1] * (b[n - k][j + 1] + u[n - k + 1][j + 1]);
  79. }
  80.  
  81. }
  82.  
  83. cout << "Значения функции u(x, t) в области D = { 0 <= X <= " << l << ", 0 <= T <= " << T << " }:\n\n";
  84.  
  85. for (j = 0; j <= floor(T / tau); j++)
  86. {
  87. for (i = 0; i <= n; i++)
  88. {
  89. cout << u[i][j] << " ";
  90. }
  91. cout << endl;
  92. }
  93. cout << "\nОсь x расположена горизонтально; ось t расположена вертикально и направлена вниз";
  94. cout << "Шаг по оси x равен " << h <<"; шаг по оси t равен " << tau << ".\n";
  95. system("pause");
  96. }
  97.  
  98. // – //
  99.  
  100. float f(float x, float t)
  101. {
  102. return 0;
  103. }
  104.  
  105. // – //
  106.  
  107. float mu_1(float t)
  108. {
  109. return 0;//2.1 + t;
  110. }
  111.  
  112. // – //
  113.  
  114. float mu_2(float t)
  115. {
  116. return 0;// 3.2 * (t + 1 / 2.71828);
  117. }
  118.  
  119. // – //
  120. float phi(float x)
  121. {
  122. return 2 * sin(2 * x);// (1.1 * pow(x, 2) + 2.1) * exp(-x);
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement