偏微分方程数值解
课程设计
学院: 专业:信息与计算科学 学号: 姓名:教师: xxxxxxxx 时间: 2011-12-3
一、问题提出
用Lax-Friedrich格式计算如下双曲型方程问题:
uu0,0x1,0t1.tx
u(x,0)cos(x),0x1.
u(0,t)u(1,t)cos(t),0t1.
其精确解为u(x,t)cos(xt)。 二、网格剖分
为了用差分方法求解上述问题,将求解区域(x,t)|0x1,0t1作剖分。
]m等分,将时间[0,1]间作n等分,并记将空间区间[0,1作区
h1/m,
n1x/j,jh
。分别称h和为空间和时间步j,0mtkk,k,n0
长。用两簇平行直线xxj,0jm,ttk,0kn将分割成矩形网格。 三、差分格式的建立 uu0………………………………(1) tx设G是x,t平面任一有界域,据Green公式:
uu
Gtx)dxdt(udtudx)
其中G。于是可将(1)式写成积分守恒形式:
(
(udtudx)0…………………………(2)
我们先从(2)式出发构造熟知的Lax格式设网格如下图所示
k+1
图一
取G为以A(j1,k),B(j1,k1),C(j1,k1)和D(j1,k)为顶点的矩形。
TABCDA为其边界,则
(udtudx)
DA
(u)dx(u)dx(u)dt(u)dt…………(3)
BC
AB
CD
右端第一个积分用梯形公式,第二个积分用中矩形公式,第三、四个积分用下矩形公式,则由(2)(3)式得到Lax-Friedrich格式
1k1
kkuk(uj1ukjj1)uuj1j10
2h
截断误差为
kk
Rkj(u)Lhuj[Lu]j
1k1k
kkkkuk(uujj1j1)uuuuj1j1jj
2htx
2k
uj
2t2
3k
h2ujO(h2),(0jm,0kn) 3
6x
所以Lax-Friedrich格式的截断误差的阶式O(h2) 令s/h:则可得差分格式为
sk1ksk1k
uku(uu)uj1,(0jm,0kn) jj1j1j1
222
u0jcos(xj)(0jm)
kk
u0cos(tk),umcos(tk),(0kn)
四、差分格式的求解
sk1ksk1ku(uu)uj1,(0jm,0kn) 差分格式ukjj1j1j1
222
写成如下矩阵形式:
1s220000
01s22000
1s220000
00
00
0
kk1
u0u1k10u1ku2
k1 k
uu
1sm2m1uk022m1
uk00m0
1s
22000
1s0220000
则需要通过对k时间层进行矩阵作用求出k+1时间层。
对上面的矩阵形式我通过C++编出如附录的程序求出数值解、真实解和误差。
对程序所得的结果进行分析如下表:
因为网格分的比较细,计算结果比较多,所以表1、表2、表3和表4分别给出不同网格得到的部分数值结果,数值解很好的逼近精确解。
表1
h1/90,1/100(s0.9)
表2
h1/900,1/1000(s0.9)
表3
h1/50,1/100(s0.5)
表4
h1/500,1/1000(s0.5)
当h(s1)时,数值解等于真实解,没有任何误差。 当s取不同值时,误差曲线如图一、图二:
图一
图二
当s0.5时,网格疏密不同,误差曲线如下图
图三
当s0.9时,网格疏密不同,误差曲线如下图
图四
由图一和图二可以得出,当s越接近1(即和h接近或m和n)时, Lax-Friedrich格式的误差越小;由图三和图四可以得出,当s相同时,网格越密(即m和n越大),Lax-Friedrich格式的误差越小。
五、稳定性分析:
用Fourier方法对Lax-Friedrich格式进行稳定性分析:
k
令ukjve
ixj
代入上述的差分格式:
vk1e
six1ixsixix
vk[ej1(ej1ej1)ej1]
2221s
vk1vk[(eiheih)(eiheih)]vk(coshissinh)
22
ixj
G(s,h)coshissinh
G(s,h)cos2hs2sin2h1(s21)sin2h
2
s1,即
h
1时,此格式恒稳定。
附录
C++程序:
#include #include
#define p 50 //x方向的分段。
#define q 100 //y(时间)方向的分段。 #define pi 3.1415926
float A[p+1][q+1]; //定义二维数组A存放数值解。 float B[p+1][q+1]; //定义二维数组B存放真实解。
void main() {
float x[p+1],t[q+1],r,s,a,b; int i,j,k,n,m,w; r=1.0/p; s=1.0/q;
a=1.0/2-(1.0/2)*(s/r); //计算0.5-0.5*s。 b=1.0/2+(1.0/2)*(s/r); //计算0.5+0.5*s。
for(j=0;j
x[j]=j*r;
A[j][0]=B[j][0]=cos(pi*x[j]); }
for(k=1;k
t[k]=k*s;
A[0][k]=B[0][k]=cos(pi*t[k]); }
for(k=1;k
t[k]=k*s;
A[p][k]=B[p][k]=-cos(pi*t[k]); }
for(k=1;k
scanf("%d",&n); //输出第n时间层的数值解。 for(i=0;i
for(i=0;i
printf("%f ",B[i][n]); printf("\n");
for(i=0;i
printf("%f ",A[i][n]-B[i][n]);//输出数值解减去真实解即误差。 printf("\n");
scanf("%d,%d",&m,&w); //输出网格中任一点数值解、真实解和误差。 printf("%f %f %f",A[m][w],B[m][w],A[m][w]-B[m][w]); printf("\n"); }
Matlab程序: 图一程序: t=0.1:0.1:1;
w1=[0.004251,0.016664,0.034592,0.052979,0.064844,0.067167,0.060746,0.047398,0.029052,0.007748];
w2=[0.000334,0.001320,0.002761,0.004362,0.005610,0.005533,0.004761,0.003521,0.001937,0.000163]; w3=[0,0,0,0,0,0,0,0,0,0];
plot(t,w1,'-bo',t,w2,'-k*',t,w3,'-rs')
图二程序:
t=0.1:0.1:1;
w1=[0.000454,0.001733,0.003580,0.005611,0.007148,0.007037,0.006015,0.004402,0.002359,0.000085];
w2=[0.000036,0.000138,0.000286,0.000448,0.000591,0.000560,0.000478,0.000348,0.000184,0.000002]; w3=[0,0,0,0,0,0,0,0,0,0];
plot(t,w1,'-bo',t,w2,'-k*',t,w3,'-rs'
图三程序:
t=0.1:0.1:1;
w1=[0.004251,0.016664,0.034592,0.052979,0.064844,0.067167,0.060746,0.047398,0.029052,0.007748];
w2=[0.000454,0.001733,0.003580,0.005611,0.007148,0.007037,0.006015,0.004402,0.002359,0.000085]; plot(t,w1,'-bd',t,w2,'-kp')
图四程序:
t=0.1:0.1:1;
w1=[0.000334,0.001320,0.002761,0.004362,0.005610,0.005533,0.004761,0.003521,0.001937,0.000163];
w2=[0.000036,0.000138,0.000286,0.000448,0.000591,0.000560,0.000478,0.000348,0.000184,0.000002]; plot(t,w1,'-bd',t,w2,'-kp')
偏微分方程数值解
课程设计
学院: 专业:信息与计算科学 学号: 姓名:教师: xxxxxxxx 时间: 2011-12-3
一、问题提出
用Lax-Friedrich格式计算如下双曲型方程问题:
uu0,0x1,0t1.tx
u(x,0)cos(x),0x1.
u(0,t)u(1,t)cos(t),0t1.
其精确解为u(x,t)cos(xt)。 二、网格剖分
为了用差分方法求解上述问题,将求解区域(x,t)|0x1,0t1作剖分。
]m等分,将时间[0,1]间作n等分,并记将空间区间[0,1作区
h1/m,
n1x/j,jh
。分别称h和为空间和时间步j,0mtkk,k,n0
长。用两簇平行直线xxj,0jm,ttk,0kn将分割成矩形网格。 三、差分格式的建立 uu0………………………………(1) tx设G是x,t平面任一有界域,据Green公式:
uu
Gtx)dxdt(udtudx)
其中G。于是可将(1)式写成积分守恒形式:
(
(udtudx)0…………………………(2)
我们先从(2)式出发构造熟知的Lax格式设网格如下图所示
k+1
图一
取G为以A(j1,k),B(j1,k1),C(j1,k1)和D(j1,k)为顶点的矩形。
TABCDA为其边界,则
(udtudx)
DA
(u)dx(u)dx(u)dt(u)dt…………(3)
BC
AB
CD
右端第一个积分用梯形公式,第二个积分用中矩形公式,第三、四个积分用下矩形公式,则由(2)(3)式得到Lax-Friedrich格式
1k1
kkuk(uj1ukjj1)uuj1j10
2h
截断误差为
kk
Rkj(u)Lhuj[Lu]j
1k1k
kkkkuk(uujj1j1)uuuuj1j1jj
2htx
2k
uj
2t2
3k
h2ujO(h2),(0jm,0kn) 3
6x
所以Lax-Friedrich格式的截断误差的阶式O(h2) 令s/h:则可得差分格式为
sk1ksk1k
uku(uu)uj1,(0jm,0kn) jj1j1j1
222
u0jcos(xj)(0jm)
kk
u0cos(tk),umcos(tk),(0kn)
四、差分格式的求解
sk1ksk1ku(uu)uj1,(0jm,0kn) 差分格式ukjj1j1j1
222
写成如下矩阵形式:
1s220000
01s22000
1s220000
00
00
0
kk1
u0u1k10u1ku2
k1 k
uu
1sm2m1uk022m1
uk00m0
1s
22000
1s0220000
则需要通过对k时间层进行矩阵作用求出k+1时间层。
对上面的矩阵形式我通过C++编出如附录的程序求出数值解、真实解和误差。
对程序所得的结果进行分析如下表:
因为网格分的比较细,计算结果比较多,所以表1、表2、表3和表4分别给出不同网格得到的部分数值结果,数值解很好的逼近精确解。
表1
h1/90,1/100(s0.9)
表2
h1/900,1/1000(s0.9)
表3
h1/50,1/100(s0.5)
表4
h1/500,1/1000(s0.5)
当h(s1)时,数值解等于真实解,没有任何误差。 当s取不同值时,误差曲线如图一、图二:
图一
图二
当s0.5时,网格疏密不同,误差曲线如下图
图三
当s0.9时,网格疏密不同,误差曲线如下图
图四
由图一和图二可以得出,当s越接近1(即和h接近或m和n)时, Lax-Friedrich格式的误差越小;由图三和图四可以得出,当s相同时,网格越密(即m和n越大),Lax-Friedrich格式的误差越小。
五、稳定性分析:
用Fourier方法对Lax-Friedrich格式进行稳定性分析:
k
令ukjve
ixj
代入上述的差分格式:
vk1e
six1ixsixix
vk[ej1(ej1ej1)ej1]
2221s
vk1vk[(eiheih)(eiheih)]vk(coshissinh)
22
ixj
G(s,h)coshissinh
G(s,h)cos2hs2sin2h1(s21)sin2h
2
s1,即
h
1时,此格式恒稳定。
附录
C++程序:
#include #include
#define p 50 //x方向的分段。
#define q 100 //y(时间)方向的分段。 #define pi 3.1415926
float A[p+1][q+1]; //定义二维数组A存放数值解。 float B[p+1][q+1]; //定义二维数组B存放真实解。
void main() {
float x[p+1],t[q+1],r,s,a,b; int i,j,k,n,m,w; r=1.0/p; s=1.0/q;
a=1.0/2-(1.0/2)*(s/r); //计算0.5-0.5*s。 b=1.0/2+(1.0/2)*(s/r); //计算0.5+0.5*s。
for(j=0;j
x[j]=j*r;
A[j][0]=B[j][0]=cos(pi*x[j]); }
for(k=1;k
t[k]=k*s;
A[0][k]=B[0][k]=cos(pi*t[k]); }
for(k=1;k
t[k]=k*s;
A[p][k]=B[p][k]=-cos(pi*t[k]); }
for(k=1;k
scanf("%d",&n); //输出第n时间层的数值解。 for(i=0;i
for(i=0;i
printf("%f ",B[i][n]); printf("\n");
for(i=0;i
printf("%f ",A[i][n]-B[i][n]);//输出数值解减去真实解即误差。 printf("\n");
scanf("%d,%d",&m,&w); //输出网格中任一点数值解、真实解和误差。 printf("%f %f %f",A[m][w],B[m][w],A[m][w]-B[m][w]); printf("\n"); }
Matlab程序: 图一程序: t=0.1:0.1:1;
w1=[0.004251,0.016664,0.034592,0.052979,0.064844,0.067167,0.060746,0.047398,0.029052,0.007748];
w2=[0.000334,0.001320,0.002761,0.004362,0.005610,0.005533,0.004761,0.003521,0.001937,0.000163]; w3=[0,0,0,0,0,0,0,0,0,0];
plot(t,w1,'-bo',t,w2,'-k*',t,w3,'-rs')
图二程序:
t=0.1:0.1:1;
w1=[0.000454,0.001733,0.003580,0.005611,0.007148,0.007037,0.006015,0.004402,0.002359,0.000085];
w2=[0.000036,0.000138,0.000286,0.000448,0.000591,0.000560,0.000478,0.000348,0.000184,0.000002]; w3=[0,0,0,0,0,0,0,0,0,0];
plot(t,w1,'-bo',t,w2,'-k*',t,w3,'-rs'
图三程序:
t=0.1:0.1:1;
w1=[0.004251,0.016664,0.034592,0.052979,0.064844,0.067167,0.060746,0.047398,0.029052,0.007748];
w2=[0.000454,0.001733,0.003580,0.005611,0.007148,0.007037,0.006015,0.004402,0.002359,0.000085]; plot(t,w1,'-bd',t,w2,'-kp')
图四程序:
t=0.1:0.1:1;
w1=[0.000334,0.001320,0.002761,0.004362,0.005610,0.005533,0.004761,0.003521,0.001937,0.000163];
w2=[0.000036,0.000138,0.000286,0.000448,0.000591,0.000560,0.000478,0.000348,0.000184,0.000002]; plot(t,w1,'-bd',t,w2,'-kp')