当前位置:文档之家› 常微分方程实验报告汇总

常微分方程实验报告汇总

常微分方程课程实验报告
实验名称 Matlab在常微分方程中的应用
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
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
1.0000 0.9756 0.9524 0.9303 0.9093 0.8892 0.8701 0.8520 0.8347 0.8183
Columns 11 through 20
0.8028 0.7880 0.7742 0.7611 0.7488 0.7374 0.7269 0.7172 0.7085 0.7008
Columns 21 through 30
0.6941 0.6886 0.6843 0.6815 0.6802 0.6809 0.6837 0.6890 0.6976 0.7102
Columns 31 through 40
0.7277 0.7519 0.7851 0.8319 0.8964 0.9910 1.1404 NaN NaN NaN
Column 41
-Inf
【4】在command窗口运行以下语句,用于求精确解:
>> y=dsolve('(x^2-1)*Dy+2*x*y-cos(x)=0','y(0)=1','x') %精确解。

相关主题