函数:
function dydt = myode(t,x,wt,w)
w = interp1(wt,w,t);
dydt=zeros(2,1);
dydt(1)+dydt(2)=-2*x(1)-w;
0= x(1)-x(2)^3;
指令:
wt = linspace(0,5,25);
w = exp(-wt);
tspan = [0 5];
ic = 1;
opts = odeset('RelTol',1e-2,'AbsTol',1e-4);
[t,x] = ode45(@(t,x) myode(t,x,wt,w), tspan, ic, opts);
plot(t,x(:,1),'-o',t,x(:,2),'-.')
遇到的错误:
'=' 运算符的使用不正确。要为变量赋值,请使用 '='。要比较值是否相等,请使用 '=='。
出错 ODEWithTimeDependentTermsExample>@(t,x)myode(t,x,wt,w) (line 6)
[t,x] = ode45(@(t,x) myode(t,x,wt,w), tspan, ic, opts);
出错 odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
出错 ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
出错 ODEWithTimeDependentTermsExample (line 6)
[t,x] = ode45(@(t,x) myode(t,x,wt,w), tspan, ic, opts);