Pythonにてforループの計算で# Q[i] の式を時間指定でtemp_new[i]の式に入れて計算したいのですが、以下のエラーが見つかりました。
何か解決策等あれば教えて頂けるとありがたいです。
(base) C:\Users\knishimura\Desktop\レーザ熱分布\00>python 00.py
File "00.py", line 48
for n in range(1, nt+1):
^
SyntaxError: invalid syntax
import
1import matplotlib.animation as animation 2import numpy as np 3import math 4 5# input parameter 6den = 2330.0 7cp = 678.0 8cond = 83.7 9temp_init = 20.0 10lx = 100e-6 11nx = 101 12tend = 400e-9 13dt = 0.000000001 #1.0e-9 14tout = 0.000000005 #5.0e-9 15a=300 16alpha = cond / (den * cp) 17dx = lx / (nx - 1) 18nt = int(tend / dt) 19nout = int(tout / dt) 20 21#initial condition 22temp = np.full(nx, temp_init) 23time = -200.0 24temp_new = np.zeros(nx) 25 26# Boundary condition 27temp[0] = temp[1] 28temp[nx-1] = temp[nx-2] # Neumann @ x=Lx 29 30# graph data array 31ims = [] 32fig = plt.figure() 33ax = fig.add_subplot(1, 1, 1) 34gx = np.zeros(nx) 35for i in range(nx): 36 gx[i] = i * dx 37 38 39# FTCS 40Q = np.zeros(nx) 41for i in range(1, nx-1): 42 # Q[i] 43 Q[i] = (math.exp(-(dt/50e-9)**2)*math.exp(-a*dx*i))/(den*cp*(50e-9)*math.sqrt(math.pi)) #単位 [℃] 44 45for n in range(-199, nt+1): 46 for i in range(1, nx-1): 47 temp_new[i] = Q[i]+temp[i] + dt * alpha * (temp[i+1] - 2.0 * temp[i] + temp[i-1]) / (dx * dx) 48 49 # update 50 for i in range(1, nx-1): 51 temp[i] = temp_new[i] 52 53 54 # Boundary condition 55 temp[0] = temp[1] 56 temp[nx-1] = temp[nx-2] # Neumann @ x=Lx 57 58 59 time += dt 60 61 if n % nout == 0: 62 print('n: {0:7d}, time: {1:8.1e}, temp: {2:10.6e}'.format(n, time, temp[nx-1])) 63 im_line = ax.plot(gx, temp, 'b') 64 im_time = ax.text(-200, 200, 'Time = {0:8.1e} [s]'.format(time)) 65 ims.append(im_line + [im_time]) 66 67# graph plot 68ax.set_xlabel('x [m]') 69ax.set_ylabel('Temperature [C]') 70ax.set_xlim(1e-6, 100e-6) 71ax.set_ylim(0, 2500) 72ax.grid() 73anm = animation.ArtistAnimation(fig, ims, interval=200) 74anm.save('animation.gif', writer='pillow') 75plt.show() 76 77
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/12/14 04:54
2021/12/14 13:55
2021/12/15 06:38
2021/12/15 11:17