odefun=@(t,x)[x(2);3*x(2)-2*x(1)+1];
[t,y]=ode45(odefun,[0:0.01:2],[1 0]);
plot(t,y)
[t y]
结果
y(0.5000)=0.7896
y= dsolve('D2y-3*Dy+2*y=1','Dy(0)=0','y(0)=1');
>> y
y =
exp(t) - exp(2*t)/2 + 1/2
>> feval(@(t)exp(t) - exp(2*t)/2 + 1/2,0.5)
ans =
0.7896
显示公式计算时,积分步长有限制,当大于某个时间步长时,积分结果会发散,而隐式没有这个问题。