复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140package com.smartmap.algorithm.equation.differential.partial.ellipsoidal; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.StringWriter; public class PoissonIteration { public static void main(String[] args) { int m = 64; int n = 32; double minX = 0; double maxX = 2; double dx = (maxX - minX) / m; double minY = 0; double maxY = 1; double dy = (maxY - minY) / n; // double xx[][] = new double[m+1][n+1]; // System.out.println("----------------------------------------"); for(int j=0; j<m+1; j++) { double value = dx * j; System.out.print(value + " "); } System.out.println(""); System.out.println("----------------------------------------"); for(int j=0; j<n+1; j++) { double value = dy * j; System.out.print(value + " "); } System.out.println(""); // for(int j=0; j<n+1; j++) { double value = dy * j; xx[0][j] = getZeroXU(value); xx[m][j] = getTwoXU(value); } for(int k=0; k<m+1; k++) { double value = dx * k; xx[k][0] = getZeroYU(value); xx[k][n] = getOneYU(value); } double error; while(true) { error = gaussSeidelCompute(xx, m, n, dx, dy); System.out.println("error: "+error); if(error < 0.00000000001) { break; } } System.out.println("--------------------------------"); for(int k=0; k<n+1; k++) { for(int j=0; j<m+1; j++) { System.out.printf(" %8.6f", xx[j][k]); } System.out.println(";"); } } public static double gaussSeidelCompute(double[][] xx, int m, int n, double dx, double dy) { double dxdy = (1.0/Math.pow(dy, 2) + 1.0/Math.pow(dx, 2)) * 2; double error = 0; for(int i=1; i<m; i++) { for(int j=1; j<n; j++) { double oldValue = xx[i][j]; double x = 0 + dx * i; double y = 0 + dy * j; double f = getF(x, y); xx[i][j] = (f + xx[i][j-1]*(1.0/Math.pow(dy, 2)) + xx[i-1][j]*(1.0/Math.pow(dx, 2)) + xx[i+1][j]*(1.0/Math.pow(dx, 2)) + xx[i][j+1]*(1.0/Math.pow(dy, 2))); xx[i][j] = xx[i][j] / dxdy; oldValue = Math.abs(xx[i][j] - oldValue); if(oldValue > error) error = oldValue; } } return error; } public static void outputAA(double[][] aa, int elementCount, String filePath, String fileName) { try { FileOutputStream fileStream = new FileOutputStream(filePath + "\"+fileName+".txt", false); OutputStream outputStream = fileStream; StringWriter streamWriter=new StringWriter(); for(int j=0; j<elementCount; j++) { for(int k=0; k<elementCount; k++) { streamWriter.write(String.format(" %8.6f", aa[j][k])); } streamWriter.write("n"); } char[] linearRingStringCharArray = streamWriter.toString().toCharArray(); for(int i=0; i<linearRingStringCharArray.length; i++) { outputStream.write(linearRingStringCharArray[i]); } fileStream.close(); streamWriter.close(); } catch (IOException e) { e.printStackTrace(); } } public static double getF(double x, double y) { double returnValue = 0; returnValue = (Math.pow(Math.PI, 2) - 1) * Math.exp(x) * Math.sin(Math.PI * y); return returnValue; } public static double getZeroXU(double y) { double returnValue = 0; returnValue = Math.sin(Math.PI * y); return returnValue; } public static double getTwoXU(double y) { double returnValue = 0; returnValue = Math.exp(2) * Math.sin(Math.PI * y); return returnValue; } public static double getZeroYU(double y) { double returnValue = 0; return returnValue; } public static double getOneYU(double y) { double returnValue = 0; return returnValue; } }
转载于:https://www.cnblogs.com/gispathfinder/p/5770063.html
最后
以上就是高贵花瓣最近收集整理的关于一维Poisson方程计算的全部内容,更多相关一维Poisson方程计算内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复