微分方程的求解
1、采用ode45求解数值解
标准形式:
【t,x]=ode45(fun,tspan,x0,options,pars)
可用odeset()验证。
示例如下:
将y和z都用x代替,化为标准型:
用matlab实现如下:
function dx=dx_funname(t,x)
dx=[-x(2)-x(3);x(1)+0.2*x(2);0.2+(x(1)-5.7)*x(3)];
end
clear
x0=[0;0;0];
[t,y]=ode45(@dx_funname,[0,100],x0);
subplot(2,1,1)
plot(t,y)
subplot(2,1,2)
plot3(y(:,1),y(:,2),y(:,3))
准确程度检验,
在命令框输入:odeset
可知RelTol: [ positive scalar {1e-3} ],即相对误差限系统默认设置是1e-3,
若对精确度要求较高,可修改上值。
options=odeset;
options.RelTol=1e-7;
[t,y]=ode45(@dx_funname,[0,100],x0);
subplot(2,1,1)
plot(t,y)
subplot(2,1,2)
plot3(y(:,1),y(:,2),y(:,3))
2、微分方程的解析解
绝大多数微分方程并没有解析解,对于少数线性微分方程可能具有解析解,可以desolve求解。
y=desolve(eqn1,eqn2…)