偏微分方程式をガウスザイデル法で解く
だんだん意味が分からなくなって来た。
using System; namespace Potential { public class MainClass { const double G = 1; const double DX = 1; private static double Ro( int x, int y ) { return 6 * x - 3 * y; } public static void Main( string[] args ) { double[][] points = new double[4][]; for ( int i = 0; i < points.Length; ++i ) points[i] = new double[4]; for ( int i = 0; i < 4; i++ ) { for ( int j = 0; j < 4; j++ ) { points[i][j] = 0.0; } } points[1][3] = 22.5; points[2][3] = 36; points[3][1] = -4.5; points[3][2] = 9; for ( int i = 0; i < 30; i++ ) { for ( int ix = 1; ix <= 2; ix++ ) { for ( int iy = 1; iy <= 2; iy++ ) { double p1 = points[ix + 1][iy] + points[ix - 1][iy] + points[ix][iy + 1] + points[ix][iy - 1]; double p2 = G * Ro( ix, iy ) * DX * DX; points[ix][iy] = p1 / 4 - p2 / 4; Console.WriteLine ( "(1,1): {0},\t(1,2): {1},\t(2,1): {2},\t(2,2):{3}", points[1][1].ToString(), points[1][2].ToString(), points[2][1].ToString(), points[2][2].ToString() ); } } } } } }