質問編集履歴

2

タグ変更

2016/08/11 03:08

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
File without changes

1

コード、タグ変更

2016/08/11 03:08

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,11 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- 調べてたり何度試したりしましたが、Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 11
5
+ 調べてたり何度試したりしましたが、今のところ各u=0.0;となります。
6
-
7
- が出ます。
8
-
9
-
10
6
 
11
7
 
12
8
 
@@ -20,4 +16,100 @@
20
16
 
21
17
  u(0,t) = u(1,t) =0, t∈(0,T),
22
18
 
23
- u(x,0) = sinπx, x∈(0,1).
19
+ u(x,0) = sinπx, x∈(0,
20
+
21
+ ```public class ex{
22
+
23
+ static public void main(String[] args){
24
+
25
+
26
+
27
+ double a = 0.0; double b = 1.0;
28
+
29
+ int M = 10;
30
+
31
+ double dx = (b-a)/(double)M;
32
+
33
+ double T = 1.0;
34
+
35
+ double t = 0.0;
36
+
37
+ double x = 0.0;
38
+
39
+ double dt = 0.5*dx*dx;
40
+
41
+ double err= 0.0;
42
+
43
+ int N = (int)(T/dt);
44
+
45
+
46
+
47
+ double ua = 0.0; double ub = 0.0;
48
+
49
+ double []u = new double[M+1];
50
+
51
+ double []v = new double[M+1];
52
+
53
+
54
+
55
+ for(int j=0; j<M+1; j++){
56
+
57
+ u[j]=Math.sin(Math.PI*x);
58
+
59
+ }
60
+
61
+ for (int k=0; k<N+1; k++){
62
+
63
+ for (int j=0; j<M-1; j++){
64
+
65
+ x = x + dx*((double)j);
66
+
67
+ v[j+1] = u[j+1] + (u[j+2] - 2*u[j+1] + u[j])*100*0.005;
68
+
69
+ t = t + dt;
70
+
71
+ }
72
+
73
+ u = v;
74
+
75
+ for (int j=0; j<M+1; j++){
76
+
77
+ if (k == 5*(int)(k/5)){
78
+
79
+ System.out.println(" t = "+t+", u["+j+"]= "+u[j]);
80
+
81
+ }
82
+
83
+
84
+
85
+ if(err < Math.abs(u[j] - exact(t,x))){
86
+
87
+ err= Math.abs(u[j] - exact(t,x));
88
+
89
+ System.out.println(" Error = "+err);
90
+
91
+ }
92
+
93
+ }
94
+
95
+
96
+
97
+ }
98
+
99
+ }
100
+
101
+
102
+
103
+ public static double exact(double t, double x){
104
+
105
+ double exact;
106
+
107
+ exact = Math.exp(-Math.PI*Math.PI*t)* Math.sin(Math.PI*x);
108
+
109
+ return exact;
110
+
111
+ }
112
+
113
+ }
114
+
115
+ ```1).