I keep getting an error. Help

3 次查看(过去 30 天)
SUNGJIN KIM
SUNGJIN KIM 2022-3-28
回答: VBBV 2022-3-28
%This progrem will use dfuncl.m
tspan = 0: 0.05: 8;
y = [0.4; 0;0];
[t , y]= ode23(@odefun, tspan, y);
plot (t, y(:, 1));
xlabel ('t');
ylabel ('y(1');
title ('problem 2.187');
function f = odefun( ~ , y )
u = 0.5;
k = 100;
m = 5;
f=zeros(2,1);
f(1) = y(2);
f(2) = -u*9.81*sign(y(2))-k*y(1)/m;
end
---------------------------------------------------------------
An error occurred while using the note: odarguments (line 95)
ODEFUN returns a vector of length 2, but the initial condition vector is of length 3.
The vector returned by ODEFUN and the initial condition vector must have the same number of elements.
Error occurred: ode23 (line 114)
odarguments(FcnHandlesUsed, solver_name, ode, tspan, y0,
options, varargin);
Error occurred: pr187 (line 5)
[t , y]= ode23(@odefun, tspan, y);

回答(1 个)

VBBV
VBBV 2022-3-28
tspan = [0:0.05: 8];
y = [0.4; 0];
[t , y]= ode45(@odefun, tspan, y);
plot (t, y(:, 1));
xlabel ('t');
ylabel ('y(1');
title ('problem 2.187');
function f = odefun( ~ , y )
u = 0.5;
k = 100;
m = 5;
f=zeros(2,1);
f(1) = y(2);
f(2) = -u*9.81*sign(y(2))-k*y(1)/m;
end
check with ode45

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by