I keep getting an error. Help

3 views (last 30 days)
SUNGJIN KIM
SUNGJIN KIM on 28 Mar 2022
Answered: VBBV on 28 Mar 2022
%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);

Answers (1)

VBBV
VBBV on 28 Mar 2022
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

Community Treasure Hunt

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

Start Hunting!