fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #include<malloc.h>
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8. #define e_eps 1.0e-8
  9. #define PI 3.14159265358979323846264338327950288
  10.  
  11. void Set_kyokai(double **U,int Nx,int Ny){
  12. int x,y;
  13. double left, top, right, bottom;
  14.  
  15. cout<<"境界条件\n";
  16. cout<<"left :";
  17. cin>>left;
  18. cout<<"right :";
  19. cin>>right;
  20. cout<<"bottom :";
  21. cin>>bottom;
  22.  
  23. double Hx = 1.0/ (double)Nx;
  24. double Hy = 1.0/(double)Ny;
  25.  
  26. /* 領域の底の境界 */
  27. for (x = 0; x <= Nx; x++){
  28. U[x][0] = bottom;
  29. printf("%lf\n",U[x][0]);
  30. }
  31. cout<<"\n";
  32.  
  33. /* 領域の上の境界 */
  34. for (x = 0; x <= Nx; x++){
  35. top = sin(PI * Hx *x);
  36. U[x][Ny] = top;
  37. printf("%lf\n",U[x][Ny]);
  38. }
  39.  
  40. /* 左の壁の境界 */
  41. for (y = 0; y <= Ny; y++){
  42. U[0][y] = left;
  43. }
  44.  
  45. /* 右の壁の境界 */
  46. for (y = 0; y <= Ny; y++){
  47. U[Nx][y] = right;
  48. }
  49. }
  50.  
  51. int main(void){
  52. int i,j,k;
  53. double uu = 0.0, d = 0.0, sum = 0.0;
  54. double errMAX;
  55.  
  56. int Nx,Ny;
  57. Nx = Ny = 0;
  58.  
  59. //計算領域の分割数
  60. cout<<"分割数の設定\n";
  61. cout<<"x軸 N :";
  62. cin>>Nx;
  63. cout<<"y軸 N :";
  64. cin>>Ny;
  65.  
  66. //緩和係数
  67. double ω = (2.0)/(1.0 + sin(PI/Nx));
  68.  
  69. double **D = new double* [Nx+1];
  70. for (i = 0; i < Ny +1; i++) {
  71. D[i] = new double[Ny+1];
  72. }
  73.  
  74. Set_kyokai(D,Nx,Ny);
  75.  
  76. for(k=1;k<=1000;k++){
  77. errMAX = 0.0;
  78. sum = 0.0;
  79. for (i = 1; i <= Nx -1; i++){
  80. for (j = 1; j <= Ny -1; j++){
  81. /* SORによる解法 */
  82. uu = D[i+1][j]+D[i-1][j]+D[i][j+1]+D[i][j-1];
  83. d = uu * ω/4.0 + (1.0 - ω)*D[i][j];
  84.  
  85. sum += fabs(d);
  86.  
  87. errMAX += fabs(d - D[i][j]);
  88. D[i][j] = d;
  89. }
  90. }
  91. if(errMAX < e_eps * sum){
  92. break;
  93. }
  94. }
  95.  
  96. cout<<"結果↓\n";
  97. for(i=0;i<Nx +1;i++){
  98. for(j=0;j<Ny +1;j++){
  99. printf("U[%d][%d] =%9f\n",i,j,D[i][j]);
  100. }
  101. cout<<"\n";
  102. }
  103. printf("\n");
  104.  
  105. for (i = 0; i < Ny +1; i++) {
  106. delete[] D[i];
  107. }
  108. delete[] D;
  109.  
  110. return 0;
  111. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:67: error: stray ‘\317’ in program
prog.cpp:67: error: stray ‘\211’ in program
prog.cpp:83: error: stray ‘\317’ in program
prog.cpp:83: error: stray ‘\211’ in program
prog.cpp:83: error: stray ‘\317’ in program
prog.cpp:83: error: stray ‘\211’ in program
prog.cpp: In function ‘void Set_kyokai(double**, int, int)’:
prog.cpp:24: warning: unused variable ‘Hy’
prog.cpp: In function ‘int main()’:
prog.cpp:67: error: expected unqualified-id before ‘=’ token
prog.cpp:83: error: expected primary-expression before ‘/’ token
prog.cpp:83: error: expected primary-expression before ‘)’ token
stdout
Standard output is empty