Matlab 已知y''-3y'+2y=0 y(0)=1 y'(0)=0 ,求y(0.5) 会的帮忙写下程序 用ode45实现最好
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/28 07:50:07
Matlab 已知y''-3y'+2y=0 y(0)=1 y'(0)=0 ,求y(0.5) 会的帮忙写下程序 用ode45实现最好
Matlab 已知y''-3y'+2y=0 y(0)=1 y'(0)=0 ,求y(0.5) 会的帮忙写下程序 用ode45实现最好
Matlab 已知y''-3y'+2y=0 y(0)=1 y'(0)=0 ,求y(0.5) 会的帮忙写下程序 用ode45实现最好
function hh
[t,y] = ODE45(@myfun,0:0.1:2,[1 0]);
[t,y]
y05=y(find(t==0.5))
plot(t,y(:,1))
%解析法验证
y2=dsolve('D2y-3*Dy+2*y=0','y(0)=1,Dy(0)=0')
t2=0:0.1:2;
y2=subs(y2,'t',t2)
hold on
plot(t2,y2,'or')
function dy=myfun(t,Y)
y=Y(1);y1=Y(2);
dydt=y1;
dy1dt=3*y1-2*y;
dy=[dydt;dy1dt];
结果:
ans =
0 1.0000 0
0.1000 0.9889 -0.2325
0.2000 0.9510 -0.5408
0.3000 0.8776 -0.9445
0.4000 0.7581 -1.4674
0.5000 0.5792 -2.1391
0.6000 0.3241 -2.9960
0.7000 -0.0277 -4.0829
0.8000 -0.5020 -5.4550
0.9000 -1.1305 -7.1801
1.0000 -1.9525 -9.3416
1.1000 -3.0167 -12.0418
1.2000 -4.3830 -15.4062
1.3000 -6.1252 -19.5890
1.4000 -8.3343 -24.7791
1.5000 -11.1222 -31.2079
1.6000 -14.6266 -39.1593
1.7000 -19.0164 -48.9806
1.8000 -24.4992 -61.0976
1.9000 -31.3296 -76.0310
2.0000 -39.8203 -94.4187
y05 =
0.5792
y2 =
-exp(2*t)+2*exp(t)
y2 =
Columns 1 through 13
1.0000 0.9889 0.9510 0.8776 0.7581 0.5792 0.3241 -0.0277 -0.5020 -1.1304 -1.9525 -3.0167 -4.3829
Columns 14 through 21
-6.1251 -8.3342 -11.1222 -14.6265 -19.0162 -24.4989 -31.3294 -39.8200