ode45解微分equation
[t,y] = ode45(odefun,tspan,y0)example
[t,y] = ode45(odefun,tspan,y0,options)example
首先编写函数文件.m作为ode45的第一个参数odefun
function y = fun(t,x0,flag,k)
%flag is a [] to mark the args 可略去不写y = fun(t,x0,k) %kequ中参数
%x0初值given
%---------------
%some global setting
lamda=1;
%---------------
y=[x0(2)*k;
lamda*x0(2)*(1-x0(1)-x0(2))-k*x0(2)];
end
调用:
[t,x]=ode45('fun',tspan,[0,tf],[],params);
%or [t,x]=ode45(@fun,tspan,[0,tf],[],params);
tspan为[0:10] 自变量范围
第三个参数为初值向量
第四个参数空阵组作flag 区别开传入fun的参数和ode45所需要的参数