常微分方程实验报告
常微分方程课程实验报告
实验名称 Matlab在常微分方程中的应用
1
2
3
4
5
6
z =
C2*exp(-2*t)+C3*exp(2*t)
【3.1】作图(先做出x 关于t ,y 关于t,z 关于t 的函数图像) : hold on ;
for c1=0:0.1:1%C1、C2和C3都大于0
for c2=0:0.1:1 for c3=0:0.1:1 t=0:0.1:1;
x=c1.*exp(2.*t)+c3.*exp(-t);
y=c1.*exp(2.*t)+c2.*exp(-t)+exp(-2.*t)*c3; z=c2.*exp(2.*t)+exp(-2.*t)*c3;
subplot(1,3,1),plot(t,x),legend('t~x') %x关于t 的函数图像 subplot(1,3,2),plot(t,y),legend('t~y') % y关于t 的函数图像
subplot(1,3,3),plot(t,z),legend('t~z') % z关于t 的函数图像
end end end
【3.2】作图(再做出x 、y 、z 的三维图像): hold on ; X=[]; Y=[]; Z=[];
for c1=0:0.2:1%C1、C2和C3都大于0
for c2=0:0.2:1 for c3=0:0.2:1 t=0:0.1:1;
x=c1.*exp(2.*t)+c3.*exp(-t);
y=c1.*exp(2.*t)+c2.*exp(-t)+exp(-2.*t)*c3; z=c2.*exp(2.*t)+exp(-2.*t)*c3; X=[X,x]; Y=[Y,y]; Z=[Z,z]; end
7
8
9
10
11
12
13
14
15
Columns 37 through 41
0.9753 1.0129 1.0521 1.0929 1.1353
第4题:
【1】编写函数M 文件——cwf1.m (用于求近似解)
function dy=cwf1(x,y)
dy=(cos(x)-2*x*y)/(x^2-1) 【2】编写脚本M 文件——chang8.m [X,Y]=ode45('cwf1' ,[0,1],1) y1=Y’ %转置
【3】则求出的近似解为(x 取值为0~1):
>>y1=
Columns 1 through 10
0.8347 0.8183
Columns 11 through 20
0.7085 0.7008
Columns 21 through 30
0.6976 0.7102
Columns 31 through 40
NaN NaN
Column 41
-Inf
【4】在command 窗口运行以下语句,用于求精确解:
>> y=dsolve('(x^2-1)*Dy+2*x*y-cos(x)=0', 'y(0)=1', 'x' ) %精确解
16
17
18
19
20
21
22
23
24