質問編集履歴
4
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,5 +1,145 @@
|
|
1
1
|
```ここに言語を入力
|
2
2
|
|
3
|
+
import matplotlib.pyplot as plt
|
4
|
+
|
5
|
+
import matplotlib.animation as animation
|
6
|
+
|
7
|
+
import numpy as np
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
# input parameter
|
12
|
+
|
13
|
+
den = 8880.0
|
14
|
+
|
15
|
+
cp = 386.0
|
16
|
+
|
17
|
+
cond = 398.0
|
18
|
+
|
19
|
+
temp_bc = 100.0
|
20
|
+
|
21
|
+
temp_init = 0.0
|
22
|
+
|
23
|
+
lx = 1.0
|
24
|
+
|
25
|
+
nx = 101
|
26
|
+
|
27
|
+
tend = 20000.0
|
28
|
+
|
29
|
+
dt = 0.1
|
30
|
+
|
31
|
+
tout = 100.0
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
alpha = cond / (den * cp)
|
36
|
+
|
37
|
+
dx = lx / (nx - 1)
|
38
|
+
|
39
|
+
nt = int(tend / dt)
|
40
|
+
|
41
|
+
nout = int(tout / dt)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
#initial condition
|
46
|
+
|
47
|
+
temp = np.full(nx, temp_init)
|
48
|
+
|
49
|
+
time = 0.0
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
temp_new = np.zeros(nx)
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# Boundary condition
|
58
|
+
|
59
|
+
temp[0] = temp_bc # Dirichlet @ x=0
|
60
|
+
|
61
|
+
temp[nx-1] = temp[nx-2] # Neumann @ x=Lx
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
# graph data array
|
66
|
+
|
67
|
+
ims = []
|
68
|
+
|
69
|
+
fig = plt.figure()
|
70
|
+
|
71
|
+
ax = fig.add_subplot(1, 1, 1)
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
gx = np.zeros(nx)
|
76
|
+
|
77
|
+
for i in range(nx):
|
78
|
+
|
79
|
+
gx[i] = i * dx
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
# time loop
|
84
|
+
|
85
|
+
for n in range(1, nt+1):
|
86
|
+
|
87
|
+
# FTCS
|
88
|
+
|
89
|
+
for i in range(1, nx-1):
|
90
|
+
|
91
|
+
temp_new[i] = temp[i] + dt * alpha * (temp[i+1] - 2.0 * temp[i] + temp[i-1]) / (dx * dx)
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
# update
|
96
|
+
|
97
|
+
for i in range(1, nx-1):
|
98
|
+
|
99
|
+
temp[i] = temp_new[i]
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
# Boundary condition
|
104
|
+
|
105
|
+
temp[0] = temp_bc # Dirichlet @ x=0
|
106
|
+
|
107
|
+
temp[nx-1] = temp[nx-2] # Neumann @ x=Lx
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
time += dt
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
if n % nout == 0:
|
116
|
+
|
117
|
+
print('n: {0:7d}, time: {1:8.1f}, temp: {2:10.6f}'.format(n, time, temp[nx-1]))
|
118
|
+
|
119
|
+
im_line = ax.plot(gx, temp, 'b')
|
120
|
+
|
121
|
+
im_time = ax.text(0, 110, 'Time = {0:8.1f} [s]'.format(time))
|
122
|
+
|
123
|
+
ims.append(im_line + [im_time])
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
# graph plot
|
128
|
+
|
129
|
+
ax.set_xlabel('x [m]')
|
130
|
+
|
131
|
+
ax.set_ylabel('Temperature [C]')
|
132
|
+
|
133
|
+
ax.grid()
|
134
|
+
|
135
|
+
anm = animation.ArtistAnimation(fig, ims, interval=50)
|
136
|
+
|
137
|
+
anm.save('animation.gif', writer='pillow')
|
138
|
+
|
139
|
+
plt.show()
|
140
|
+
|
141
|
+
``````ここに言語を入力
|
142
|
+
|
3
143
|
コード
|
4
144
|
|
5
145
|
```### 前提・実現したいこと
|
@@ -42,143 +182,7 @@
|
|
42
182
|
|
43
183
|
### 該当のソースコード
|
44
184
|
|
45
|
-
|
185
|
+
|
46
|
-
|
47
|
-
import matplotlib.animation as animation
|
48
|
-
|
49
|
-
import numpy as np
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
# input parameter
|
54
|
-
|
55
|
-
den = 8880.0
|
56
|
-
|
57
|
-
cp = 386.0
|
58
|
-
|
59
|
-
cond = 398.0
|
60
|
-
|
61
|
-
temp_bc = 100.0
|
62
|
-
|
63
|
-
temp_init = 0.0
|
64
|
-
|
65
|
-
lx = 1.0
|
66
|
-
|
67
|
-
nx = 101
|
68
|
-
|
69
|
-
tend = 20000.0
|
70
|
-
|
71
|
-
dt = 0.1
|
72
|
-
|
73
|
-
tout = 100.0
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
alpha = cond / (den * cp)
|
78
|
-
|
79
|
-
dx = lx / (nx - 1)
|
80
|
-
|
81
|
-
nt = int(tend / dt)
|
82
|
-
|
83
|
-
nout = int(tout / dt)
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
#initial condition
|
88
|
-
|
89
|
-
temp = np.full(nx, temp_init)
|
90
|
-
|
91
|
-
time = 0.0
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
temp_new = np.zeros(nx)
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
# Boundary condition
|
100
|
-
|
101
|
-
temp[0] = temp_bc # Dirichlet @ x=0
|
102
|
-
|
103
|
-
temp[nx-1] = temp[nx-2] # Neumann @ x=Lx
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
# graph data array
|
108
|
-
|
109
|
-
ims = []
|
110
|
-
|
111
|
-
fig = plt.figure()
|
112
|
-
|
113
|
-
ax = fig.add_subplot(1, 1, 1)
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
gx = np.zeros(nx)
|
118
|
-
|
119
|
-
for i in range(nx):
|
120
|
-
|
121
|
-
gx[i] = i * dx
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
# time loop
|
126
|
-
|
127
|
-
for n in range(1, nt+1):
|
128
|
-
|
129
|
-
# FTCS
|
130
|
-
|
131
|
-
for i in range(1, nx-1):
|
132
|
-
|
133
|
-
temp_new[i] = temp[i] + dt * alpha * (temp[i+1] - 2.0 * temp[i] + temp[i-1]) / (dx * dx)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# update
|
138
|
-
|
139
|
-
for i in range(1, nx-1):
|
140
|
-
|
141
|
-
temp[i] = temp_new[i]
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
# Boundary condition
|
146
|
-
|
147
|
-
temp[0] = temp_bc # Dirichlet @ x=0
|
148
|
-
|
149
|
-
temp[nx-1] = temp[nx-2] # Neumann @ x=Lx
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
time += dt
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
if n % nout == 0:
|
158
|
-
|
159
|
-
print('n: {0:7d}, time: {1:8.1f}, temp: {2:10.6f}'.format(n, time, temp[nx-1]))
|
160
|
-
|
161
|
-
im_line = ax.plot(gx, temp, 'b')
|
162
|
-
|
163
|
-
im_time = ax.text(0, 110, 'Time = {0:8.1f} [s]'.format(time))
|
164
|
-
|
165
|
-
ims.append(im_line + [im_time])
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
# graph plot
|
170
|
-
|
171
|
-
ax.set_xlabel('x [m]')
|
172
|
-
|
173
|
-
ax.set_ylabel('Temperature [C]')
|
174
|
-
|
175
|
-
ax.grid()
|
176
|
-
|
177
|
-
anm = animation.ArtistAnimation(fig, ims, interval=50)
|
178
|
-
|
179
|
-
anm.save('animation.gif', writer='pillow')
|
180
|
-
|
181
|
-
plt.show()
|
182
186
|
|
183
187
|
|
184
188
|
|
3
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -38,11 +38,11 @@
|
|
38
38
|
|
39
39
|
|
40
40
|
|
41
|
-
```
|
42
41
|
|
43
|
-
エラーメッセージ
|
44
42
|
|
43
|
+
### 該当のソースコード
|
44
|
+
|
45
|
-
|
45
|
+
import matplotlib.pyplot as plt
|
46
46
|
|
47
47
|
import matplotlib.animation as animation
|
48
48
|
|
@@ -182,16 +182,6 @@
|
|
182
182
|
|
183
183
|
|
184
184
|
|
185
|
-
コード
|
186
|
-
|
187
|
-
```
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
### 該当のソースコード
|
192
|
-
|
193
|
-
|
194
|
-
|
195
185
|
|
196
186
|
|
197
187
|
### 試したこと
|
2
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,150 +42,154 @@
|
|
42
42
|
|
43
43
|
エラーメッセージ
|
44
44
|
|
45
|
+
``````import matplotlib.pyplot as plt
|
46
|
+
|
47
|
+
import matplotlib.animation as animation
|
48
|
+
|
49
|
+
import numpy as np
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
# input parameter
|
54
|
+
|
55
|
+
den = 8880.0
|
56
|
+
|
57
|
+
cp = 386.0
|
58
|
+
|
59
|
+
cond = 398.0
|
60
|
+
|
61
|
+
temp_bc = 100.0
|
62
|
+
|
63
|
+
temp_init = 0.0
|
64
|
+
|
65
|
+
lx = 1.0
|
66
|
+
|
67
|
+
nx = 101
|
68
|
+
|
69
|
+
tend = 20000.0
|
70
|
+
|
71
|
+
dt = 0.1
|
72
|
+
|
73
|
+
tout = 100.0
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
alpha = cond / (den * cp)
|
78
|
+
|
79
|
+
dx = lx / (nx - 1)
|
80
|
+
|
81
|
+
nt = int(tend / dt)
|
82
|
+
|
83
|
+
nout = int(tout / dt)
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
#initial condition
|
88
|
+
|
89
|
+
temp = np.full(nx, temp_init)
|
90
|
+
|
91
|
+
time = 0.0
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
temp_new = np.zeros(nx)
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
# Boundary condition
|
100
|
+
|
101
|
+
temp[0] = temp_bc # Dirichlet @ x=0
|
102
|
+
|
103
|
+
temp[nx-1] = temp[nx-2] # Neumann @ x=Lx
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
# graph data array
|
108
|
+
|
109
|
+
ims = []
|
110
|
+
|
111
|
+
fig = plt.figure()
|
112
|
+
|
113
|
+
ax = fig.add_subplot(1, 1, 1)
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
gx = np.zeros(nx)
|
118
|
+
|
119
|
+
for i in range(nx):
|
120
|
+
|
121
|
+
gx[i] = i * dx
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
# time loop
|
126
|
+
|
127
|
+
for n in range(1, nt+1):
|
128
|
+
|
129
|
+
# FTCS
|
130
|
+
|
131
|
+
for i in range(1, nx-1):
|
132
|
+
|
133
|
+
temp_new[i] = temp[i] + dt * alpha * (temp[i+1] - 2.0 * temp[i] + temp[i-1]) / (dx * dx)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
# update
|
138
|
+
|
139
|
+
for i in range(1, nx-1):
|
140
|
+
|
141
|
+
temp[i] = temp_new[i]
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
# Boundary condition
|
146
|
+
|
147
|
+
temp[0] = temp_bc # Dirichlet @ x=0
|
148
|
+
|
149
|
+
temp[nx-1] = temp[nx-2] # Neumann @ x=Lx
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
time += dt
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
if n % nout == 0:
|
158
|
+
|
159
|
+
print('n: {0:7d}, time: {1:8.1f}, temp: {2:10.6f}'.format(n, time, temp[nx-1]))
|
160
|
+
|
161
|
+
im_line = ax.plot(gx, temp, 'b')
|
162
|
+
|
163
|
+
im_time = ax.text(0, 110, 'Time = {0:8.1f} [s]'.format(time))
|
164
|
+
|
165
|
+
ims.append(im_line + [im_time])
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
# graph plot
|
170
|
+
|
171
|
+
ax.set_xlabel('x [m]')
|
172
|
+
|
173
|
+
ax.set_ylabel('Temperature [C]')
|
174
|
+
|
175
|
+
ax.grid()
|
176
|
+
|
177
|
+
anm = animation.ArtistAnimation(fig, ims, interval=50)
|
178
|
+
|
179
|
+
anm.save('animation.gif', writer='pillow')
|
180
|
+
|
181
|
+
plt.show()
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
コード
|
186
|
+
|
45
187
|
```
|
46
188
|
|
47
189
|
|
48
190
|
|
49
191
|
### 該当のソースコード
|
50
192
|
|
51
|
-
```こ```import matplotlib.pyplot as plt
|
52
|
-
|
53
|
-
import matplotlib.animation as animation
|
54
|
-
|
55
|
-
import numpy as np
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# input parameter
|
60
|
-
|
61
|
-
den = 8880.0
|
62
|
-
|
63
|
-
cp = 386.0
|
64
|
-
|
65
|
-
cond = 398.0
|
66
|
-
|
67
|
-
temp_bc = 100.0
|
68
|
-
|
69
|
-
temp_init = 0.0
|
70
|
-
|
71
|
-
lx = 1.0
|
72
|
-
|
73
|
-
nx = 101
|
74
|
-
|
75
|
-
tend = 20000.0
|
76
|
-
|
77
|
-
dt = 0.1
|
78
|
-
|
79
|
-
tout = 100.0
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
alpha = cond / (den * cp)
|
84
|
-
|
85
|
-
dx = lx / (nx - 1)
|
86
|
-
|
87
|
-
nt = int(tend / dt)
|
88
|
-
|
89
|
-
nout = int(tout / dt)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
#initial condition
|
94
|
-
|
95
|
-
temp = np.full(nx, temp_init)
|
96
|
-
|
97
|
-
time = 0.0
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
temp_new = np.zeros(nx)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# Boundary condition
|
106
|
-
|
107
|
-
temp[0] = temp_bc # Dirichlet @ x=0
|
108
|
-
|
109
|
-
temp[nx-1] = temp[nx-2] # Neumann @ x=Lx
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
# graph data array
|
114
|
-
|
115
|
-
ims = []
|
116
|
-
|
117
|
-
fig = plt.figure()
|
118
|
-
|
119
|
-
ax = fig.add_subplot(1, 1, 1)
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
gx = np.zeros(nx)
|
124
|
-
|
125
|
-
for i in range(nx):
|
126
|
-
|
127
|
-
gx[i] = i * dx
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
# time loop
|
132
|
-
|
133
|
-
for n in range(1, nt+1):
|
134
|
-
|
135
|
-
# FTCS
|
136
|
-
|
137
|
-
for i in range(1, nx-1):
|
138
|
-
|
139
|
-
temp_new[i] = temp[i] + dt * alpha * (temp[i+1] - 2.0 * temp[i] + temp[i-1]) / (dx * dx)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
# update
|
144
|
-
|
145
|
-
for i in range(1, nx-1):
|
146
|
-
|
147
|
-
temp[i] = temp_new[i]
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
# Boundary condition
|
152
|
-
|
153
|
-
temp[0] = temp_bc # Dirichlet @ x=0
|
154
|
-
|
155
|
-
temp[nx-1] = temp[nx-2] # Neumann @ x=Lx
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
time += dt
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
if n % nout == 0:
|
164
|
-
|
165
|
-
print('n: {0:7d}, time: {1:8.1f}, temp: {2:10.6f}'.format(n, time, temp[nx-1]))
|
166
|
-
|
167
|
-
im_line = ax.plot(gx, temp, 'b')
|
168
|
-
|
169
|
-
im_time = ax.text(0, 110, 'Time = {0:8.1f} [s]'.format(time))
|
170
|
-
|
171
|
-
ims.append(im_line + [im_time])
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
# graph plot
|
176
|
-
|
177
|
-
ax.set_xlabel('x [m]')
|
178
|
-
|
179
|
-
ax.set_ylabel('Temperature [C]')
|
180
|
-
|
181
|
-
ax.grid()
|
182
|
-
|
183
|
-
anm = animation.ArtistAnimation(fig, ims, interval=50)
|
184
|
-
|
185
|
-
anm.save('animation.gif', writer='pillow')
|
186
|
-
|
187
|
-
plt.show()
|
188
|
-
|
189
193
|
|
190
194
|
|
191
195
|
|
1
書式の改善
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
コード
|
4
|
+
|
1
|
-
### 前提・実現したいこと
|
5
|
+
```### 前提・実現したいこと
|
2
6
|
|
3
7
|
プログラミング未経験の者です。以下リンク、科学技術計算講座3-熱伝導方程式シミュレーション-FTCS法のプログラミングのなかで
|
4
8
|
|
@@ -44,7 +48,7 @@
|
|
44
48
|
|
45
49
|
### 該当のソースコード
|
46
50
|
|
47
|
-
import matplotlib.pyplot as plt
|
51
|
+
```こ```import matplotlib.pyplot as plt
|
48
52
|
|
49
53
|
import matplotlib.animation as animation
|
50
54
|
|
@@ -184,6 +188,8 @@
|
|
184
188
|
|
185
189
|
|
186
190
|
|
191
|
+
|
192
|
+
|
187
193
|
### 試したこと
|
188
194
|
|
189
195
|
|