I keep getting an error. Help

1 回表示 (過去 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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by