I keep getting an error. Help

3 vues (au cours des 30 derniers jours)
SUNGJIN KIM
SUNGJIN KIM le 28 Mar 2022
Réponse apportée : VBBV le 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);

Réponses (1)

VBBV
VBBV le 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

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by