#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>
#include <iostream>
#include <string>
using namespace std;
#define e_eps 1.0e-8
#define PI 3.14159265358979323846264338327950288
void Set_kyokai( double ** U,int Nx,int Ny) {
int x,y;
double left, top, right, bottom;
cout << "境界条件\n " ;
cout << "left :" ;
cin >> left;
cout << "right :" ;
cin >> right;
cout << "bottom :" ;
cin >> bottom;
double Hx = 1.0 / ( double ) Nx;
double Hy = 1.0 / ( double ) Ny;
/* 領域の底の境界 */
for ( x = 0 ; x <= Nx; x++ ) {
U[ x] [ 0 ] = bottom;
printf ( "%lf\n " ,U[ x] [ 0 ] ) ;
}
cout << "\n " ;
/* 領域の上の境界 */
for ( x = 0 ; x <= Nx; x++ ) {
top = sin ( PI * Hx * x) ;
U[ x] [ Ny] = top;
printf ( "%lf\n " ,U[ x] [ Ny] ) ;
}
/* 左の壁の境界 */
for ( y = 0 ; y <= Ny; y++ ) {
U[ 0 ] [ y] = left;
}
/* 右の壁の境界 */
for ( y = 0 ; y <= Ny; y++ ) {
U[ Nx] [ y] = right;
}
}
int main( void ) {
int i,j,k;
double uu = 0.0 , d = 0.0 , sum = 0.0 ;
double errMAX;
int Nx,Ny;
Nx = Ny = 0 ;
//計算領域の分割数
cout << "分割数の設定\n " ;
cout << "x軸 N :" ;
cin >> Nx;
cout << "y軸 N :" ;
cin >> Ny;
//緩和係数
double ω = ( 2.0 ) / ( 1.0 + sin ( PI/ Nx) ) ;
double ** D = new double * [ Nx+ 1 ] ;
for ( i = 0 ; i < Ny + 1 ; i++ ) {
D[ i] = new double [ Ny+ 1 ] ;
}
Set_kyokai( D,Nx,Ny) ;
for ( k= 1 ; k<= 1000 ; k++ ) {
errMAX = 0.0 ;
sum = 0.0 ;
for ( i = 1 ; i <= Nx - 1 ; i++ ) {
for ( j = 1 ; j <= Ny - 1 ; j++ ) {
/* SORによる解法 */
uu = D[ i+ 1 ] [ j] + D[ i- 1 ] [ j] + D[ i] [ j+ 1 ] + D[ i] [ j- 1 ] ;
d = uu * ω/ 4.0 + ( 1.0 - ω) * D[ i] [ j] ;
sum + = fabs ( d) ;
errMAX + = fabs ( d - D[ i] [ j] ) ;
D[ i] [ j] = d;
}
}
if ( errMAX < e_eps * sum) {
break ;
}
}
cout << "結果↓\n " ;
for ( i= 0 ; i< Nx + 1 ; i++ ) {
for ( j= 0 ; j< Ny + 1 ; j++ ) {
printf ( "U[%d][%d] =%9f\n " ,i,j,D[ i] [ j] ) ;
}
cout << "\n " ;
}
printf ( "\n " ) ;
for ( i = 0 ; i < Ny + 1 ; i++ ) {
delete [ ] D[ i] ;
}
delete [ ] D;
return 0 ;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPG1hdGguaD4KI2luY2x1ZGU8bWFsbG9jLmg+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBlX2VwcyAxLjBlLTgKI2RlZmluZSBQSSAzLjE0MTU5MjY1MzU4OTc5MzIzODQ2MjY0MzM4MzI3OTUwMjg4CiAKdm9pZCBTZXRfa3lva2FpKGRvdWJsZSAqKlUsaW50IE54LGludCBOeSl7CiAgICAgICAgaW50IHgseTsKICAgICAgICBkb3VibGUgbGVmdCwgdG9wLCByaWdodCwgYm90dG9tOwogCiAgICAgICAgY291dDw8IuWig+eVjOadoeS7tlxuIjsKICAgICAgICBjb3V0PDwibGVmdCA6IjsKICAgICAgICBjaW4+PmxlZnQ7CiAgICAgICAgY291dDw8InJpZ2h0IDoiOwogICAgICAgIGNpbj4+cmlnaHQ7CiAgICAgICAgY291dDw8ImJvdHRvbSA6IjsKICAgICAgICBjaW4+PmJvdHRvbTsKIAogICAgICAgIGRvdWJsZSBIeCA9IDEuMC8gKGRvdWJsZSlOeDsKICAgICAgICBkb3VibGUgSHkgPSAxLjAvKGRvdWJsZSlOeTsKIAogICAgICAgIC8qIOmgmOWfn+OBruW6leOBruWig+eVjCAqLwogICAgICAgIGZvciAoeCA9IDA7IHggPD0gTng7IHgrKyl7CiAgICAgICAgICAgICAgICBVW3hdWzBdID0gYm90dG9tOwogICAgICAgICAgICAgICAgcHJpbnRmKCIlbGZcbiIsVVt4XVswXSk7CiAgICAgICAgfQogICAgICAgIGNvdXQ8PCJcbiI7CiAKICAgICAgICAvKiDpoJjln5/jga7kuIrjga7looPnlYwgKi8KICAgICAgICBmb3IgKHggPSAwOyB4IDw9IE54OyB4KyspewogICAgICAgICAgICAgICAgdG9wID0gc2luKFBJICogSHggKngpOwogICAgICAgICAgICAgICAgVVt4XVtOeV0gPSB0b3A7CiAgICAgICAgICAgICAgICBwcmludGYoIiVsZlxuIixVW3hdW055XSk7CiAgICAgICAgfQogCiAgICAgICAgLyog5bem44Gu5aOB44Gu5aKD55WMICovCiAgICAgICAgZm9yICh5ID0gMDsgeSA8PSBOeTsgeSsrKXsKICAgICAgICAgICAgICAgIFVbMF1beV0gPSBsZWZ0OwogICAgICAgIH0KIAogICAgICAgIC8qIOWPs+OBruWjgeOBruWig+eVjCAqLwogICAgICAgIGZvciAoeSA9IDA7IHkgPD0gTnk7IHkrKyl7CiAgICAgICAgICAgICAgICBVW054XVt5XSA9IHJpZ2h0OwogICAgICAgIH0KfQogCmludCBtYWluKHZvaWQpewogICAgICAgIGludCBpLGosazsKICAgICAgICBkb3VibGUgdXUgPSAwLjAsIGQgPSAwLjAsIHN1bSA9IDAuMDsKICAgICAgICBkb3VibGUgZXJyTUFYOwogCiAgICAgICAgaW50IE54LE55OwogICAgICAgIE54ID0gTnkgPSAwOwogCiAgICAgICAgLy/oqIjnrpfpoJjln5/jga7liIblibLmlbAKICAgICAgICBjb3V0PDwi5YiG5Ymy5pWw44Gu6Kit5a6aXG4iOwogICAgICAgIGNvdXQ8PCJ46Lu4IE4gOiI7CiAgICAgICAgY2luPj5OeDsKICAgICAgICBjb3V0PDwieei7uCBOIDoiOwogICAgICAgIGNpbj4+Tnk7CiAKICAgICAgICAvL+e3qeWSjOS/guaVsAogICAgICAgIGRvdWJsZSDPiSA9ICgyLjApLygxLjAgKyBzaW4oUEkvTngpKTsKICAgICAgICAKICAgICAgICBkb3VibGUgKipEID0gbmV3IGRvdWJsZSogW054KzFdOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBOeSArMTsgaSsrKSB7CiAgICAgICAgICAgICAgICBEW2ldID0gbmV3IGRvdWJsZVtOeSsxXTsKICAgICAgICB9CiAKICAgICAgICBTZXRfa3lva2FpKEQsTngsTnkpOwogCiAgICAgICAgZm9yKGs9MTtrPD0xMDAwO2srKyl7CiAgICAgICAgICAgICAgICBlcnJNQVggPSAwLjA7CiAgICAgICAgICAgICAgICBzdW0gPSAwLjA7CiAgICAgICAgICAgICAgICBmb3IgKGkgPSAxOyBpIDw9IE54IC0xOyBpKyspewogICAgICAgICAgICAgICAgICAgICAgICBmb3IgKGogPSAxOyBqIDw9IE55IC0xOyBqKyspewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC8qIFNPUuOBq+OCiOOCi+ino+azlSAqLyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdXUgPSBEW2krMV1bal0rRFtpLTFdW2pdK0RbaV1baisxXStEW2ldW2otMV07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZCA9IHV1ICogz4kvNC4wICsgKDEuMCAtIM+JKSpEW2ldW2pdOwogCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3VtICs9IGZhYnMoZCk7CiAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBlcnJNQVggKz0gZmFicyhkIC0gRFtpXVtqXSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRFtpXVtqXSA9IGQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmKGVyck1BWCA8IGVfZXBzICogc3VtKXsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQogCiAgICAgICAgY291dDw8Iue1kOaenOKGk1xuIjsKICAgICAgICBmb3IoaT0wO2k8TnggKzE7aSsrKXsKICAgICAgICAgICAgICAgIGZvcihqPTA7ajxOeSArMTtqKyspewogICAgICAgICAgICAgICAgICAgICAgICBwcmludGYoIlVbJWRdWyVkXSA9JTlmXG4iLGksaixEW2ldW2pdKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGNvdXQ8PCJcbiI7CiAgICAgICAgfQogICAgICAgIHByaW50ZigiXG4iKTsKICAgICAgICAKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgTnkgKzE7IGkrKykgewogICAgICAgICAgICAgICAgZGVsZXRlW10gRFtpXTsKICAgICAgICB9CiAgICAgICAgZGVsZXRlW10gRDsKIAogICAgICAgIHJldHVybiAwOwp9IA==
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