所以我需要求解 x''(t) = -x(t)^p 初始条件 x(0)= 0 和 v(0) = x'(0) = v_o = 1。参数 p 的值是 1。
这就是我所拥有的:
function [t, velocity, x] = ode_oscilation(p)
y=[0;0;0];
% transform system to the canonical form
function y = oscilation_equation(x,p)
y=zeros(2,1);
y(1)=y(2);
y(2)=-(x)^p;
% to make matlab happy we need to return a column vector
% so we transpose (note the dot in .')
y=y.';
end
tspan=[0, 30]; % time interval of interest
[t,velocity,x] = ode45(@oscilation_equation, tspan, 1);
t = y(:,1);
xposition=y(:,3);
velocity=y(:,2);
end
这是我收到的错误消息:
ode_oscillation(1) 使用 odearguments 时出错(第 91 行) ODE_OSCILLATION/OSCILATION_EQUATION 必须返回列向量。
ode45 错误(第 114 行)[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
ode_oscillation 错误(第 17 行)[t,velocity,x] = ode45(@oscilation_equation, tspan,1);