-
马上要参加亚太杯啦,听说今年亚太杯有经典的物理题,没什么好说的,盘它!
-
偏微分方程的数值解十分重要
椭圆型偏微分方程(不含时)
数值解法
二维拉普拉斯方程
例
边界条件
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import math
limit = 1000 #迭代次数极限
N = 101 #X轴方向分割次数
M = 101 #Y轴方向分割次数
def iteration(u):
global N
global M
u_next = np.zeros((M,N))
for i in range(1,N-1):
for j in range(1,M-1):
u_next[i][j] = 0.25*(u[i][j-1]+u[i-1][j]+u[i+1][j]+u[i][j+1])
for i in range(1,N-1):
for j in range(1,M-1):
u[i][j] = u_next[i][j]
u = np.zeros((M,N))
for i in range(M):
u[0][i] = math.sin(2*math.pi*i/(M-1))
for i in range(N):
u[-1][i] = math.log(1+i)/10
for i in range(M):
u[i][-1] = math.cos(i)
for i in range(N):
u[i][0] = math.e ** (i/100)
for i in range(limit):
iteration(u)
x = np.arange(0,N)
y = np.arange(0,M)
X,Y = np.meshgrid(x,y)
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_wireframe(X,Y,u)
plt.show()
二维泊松方程
例
边界条件:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import math
limit = 1000 #迭代次数极限
N = 101 #X轴方向分割次数
M = 101 #Y轴方向分割次数
h = 1
f = lambda x,y : x+y
def iteration(u):
global N
global M
u_next = np.zeros((M,N))
for i in range(1,N-1):
for j in range(1,M-1):
u_next[i][j] = 0.25*(u[i][j-1]+u[i-1][j]+u[i+1][j]+u[i][j+1]-h**2*f(i,j))
for i in range(1,N-1):
for j in range(1,M-1):
u[i][j] = u_next[i][j]
u = np.zeros((M,N))
for i in range(M):
u[0][i] = math.sin(2*math.pi*i/(M-1))
for i in range(N):
u[-1][i] = math.log(1+i)/10
for i in range(M):
u[i][-1] = math.cos(i)
for i in range(N):
u[i][0] = math.e ** (i/100)
for i in range(limit):
iteration(u)
x = np.arange(0,N)
y = np.arange(0,M)
X,Y = np.meshgrid(x,y)
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_wireframe(X,Y,u)
plt.show()
二阶抛物型偏微分方程
一维热传导方程
边界条件:
空间步长与时间步长
递推关系:
例:
import numpy as np
import matplotlib.pyplot as plt
#参量设置
l = 1
lambde = 1.0
start_time = 0.0
end_time = 10
h = 0.05
tau = 0.001
K = lambde * tau /h**2
#参量设置结束
#数值解向量
U = np.zeros((int((l)/h),int((end_time-start_time)/tau)))
#数值解向量组设置结束
#边界条件设置
for j in range(int((end_time-start_time)/tau)):
U[0,j] = np.sin(j)
U[-1,j] = 0.0
#边界条件设置结束
#初始条件设置
for i in range(int(l/h)):
U[i,0] = 0
#初始条件设置结束
#时域差分法
for j in range(int((end_time-start_time)/tau)-1):
for i in range(1,int(l/h)-1):
try:
U[i,j+1] = K*U[i+1,j]+(1-2*K)*U[i,j]+K*U[i-1,j]
except:
print("i,j",i," ",j)
#时域差分法设置结束
#数据可视化
for i in range(10):
try:
u = U[:,i*1000]
plt.plot(range(len(u)),u)
plt.pause(0.5)
except:
print("超出时域范围")
for i in range(20):
try:
u = U[i,:]
plt.plot(range(len(u)),u)
plt.pause(0.5)
except:
print("超出长度范围")
二维热传导方程
边界条件:
递推关系:
双曲型方程
二维波动方程
边界条件:
递推关系:
迎风法的收敛条件
例:
import numpy as np
import matplotlib.pyplot as plt
#参量设置
c = 1.0
start_time,end_time = 0.0,1.0
start_x,end_x = 0.0,1.0
start_y,end_y = 0.0,1.0
tau = 0.01
hx = 0.02
hy = 0.02
rx = c**2*tau**2/hx**2
ry = c**2*tau**2/hy**2
#参量设置结束
#步长检验
assert(4*c**2*tau**2/(hx**2+hy**2)<=1),"不符合迎风法收敛条件"
#步长检验结束
#数值解向量
X,Y = np.meshgrid(np.arange(0,int((end_x-start_x)),hx),np.arange(0,int((end_y-start_y)),hy))
U = np.zeros((int((end_time-start_time)/tau),int((end_x-start_x)/hx),int((end_y-start_y)/hy)))
#数值解向量组设置结束
#初始条件设置
U[0] = np.sin(2*np.pi*X)
U[1] = np.cos(2*np.pi*Y)
#初始条件设置结束
#有限差分法
for k in range(2,int((end_time-start_time)/tau)):
for i in range(1,int((end_x-start_x)/hx)-1):
for j in range(1,int((end_y-start_y)/hy)-1):
try:
U[k,i,j] = rx*(U[k-1,i-1,j]+U[k-1,i+1,j]) + ry*(U[k-1,i,j-1] + U[k-1,i,j+1]) + 2*(1-rx-ry)*U[k-1,i,j] - U[k-2,i,j]
except:
print("k,i,j",k," ",i," ",j,"")
#有限差分法设置结束
#数据可视化
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111,projection="3d")
for i in range(int((end_time-start_time)/tau)):
surf = ax.plot_surface(X,Y,U[i,:,:],rstride=2,cstride=2,cmap='rainbow')
plt.pause(0.01)
plt.cla()
- 很好,我发现需要再多写一点字来提高文章的质量,尽管我觉得这篇文章的质量已经不低了
- 期末来了。正好碰上了亚太杯
- 哎,光学+原物+数理方法!都是好课,爱了爱了
- 偏微分方程 好课好课
- 高等代数 好课好课
- 常微分方程 好课好课
- 数数看,这学期学了几个专业学分 光学4 原物3 数理方法4 偏微分方程4 高等代数5 常微分方程4 共计 24专业学分。
偏微分方程内双语词汇
- 专门为美赛与亚太杯准备
- absoulte error 决对误差
- absoulte tolerance 容忍限
- machine precision 机器精度
- error estimate 误差估计
- exact solution 精确解
- adaptive mesh 适应性网格
- mixed boundary condition 混合边界条件
- Neuman boundary condition Neuman 边界条件
- boundary condition 边界条件
- converge 收敛
- contour plot 等值线图
- coordinate 坐标系
- decomposed 分解的
- decomposed geometry matrix 分解几何矩阵
- diagonal matrix 对角矩阵
- elliptic 椭圆型的
- hyperbolic 双曲线型的
- parabolic 抛物型的
插值双语词汇
- approximation 逼近
- spline approximation 样条拟合
- spline function 样条函数
- spline surface 样条曲线
- multivariate function 多元函数
- univariate function 一元函数
-
a spline of polynomial piece 分段多项式样条 - bivariate spline function 二元样条函数
- cubic interpolation 三次插值
- cubic polynomial 三次多项式
- cubic smoothing splinr 三次平滑样条
- weight 权重
- tolerance 允许精度
- degree of freedom 自由度
优化双语词汇
- unconstrained 无约束的
- semi-infinitely problem 半无限问题
- robust 稳健的
- over-determined 超定的
- exceede 溢出的
- feasible 可行的
- nolinear 非线性的
- objection function 目标函数
- multiobjective 多目标的
- argument 变量
- termination message 终止信息
- optimize 优化
- optimizer 求解器
- rasiduals 残差
数理统计双语词汇
- acceptable region 接受域
- convariance 协方差分析
- association 相关性
- availability 有效性
- binomial distribution 二项分布
- cluster analysis 聚类分析
- components 构成,分量
- confidence interval 置信区间
- likelihood ratio test 似然比检验