function yp = nonlinear(t,y)
e=0.2;
yp(1)=y(2);
yp(2) = (-y(1)-e*y(1)^3);
代码
tspan = [0 20];
y0=[0;0]
[t,y]=ode45('nonlinear',tspan,y0)
plot (t,y(:,1))
grid
xlabel('time')
ylabel('u')
title ('u vs. t')
hold on;
当我执行这个时,它说非线性必须返回一个列向量。对不起,这真的是菜鸟。
Error using odearguments (line 90)
NONLINEAR must return a column vector.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Project1 (line 3)
[t,y]=ode45('nonlinear',tspan,y0)