Why I'm keep getting these errors? Please help!

9 ビュー (過去 30 日間)
Nawal
Nawal 2013 年 7 月 31 日
コメント済み: Walter Roberson 2019 年 1 月 21 日
I'm writing a program and I can't finish it because I'm keep getting these error below....
Error using odearguments (line 93)
MY_FUNCTION returns a vector of length 1, but the length of initial conditions vector is 2.
The vector returned by MY_FUNCTION and the initial conditions vector must have the same number of elements.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in p3 (line 10)
[ts,xs]= ode45(@my_function,[0,10],[5,0])
My script file :
function ys = my_function (t,y)
W= 50; % weight in lb.
g= 32.2 ; % acceleration due to gravity ( ft/s^2)
theta=(35*pi)/(180) ; % radian
Mk=0.2; % no units
L= 12 ;% length in ft.
ys = (( 3 ) *( ( (1-(Mk^2))* g* sin(y(1))) - ( 2*Mk*g*cos(y(1))) + (Mk*((y(2))^2)))) / ( L*(2-(Mk^2)));
And the ode45 part is :
% problem # 3
W= 50; % weight in lb.
g= 32.2 ; % acceleration due to gravity ( ft/s^2)
theta=(35*pi)/(180) ; % radian
Mk=0.2; % no units
L= 12 ;% length in ft.
[ts,xs]= ode45(@my_function,[0,10],[5,0])

回答 (2 件)

Richard Brown
Richard Brown 2013 年 7 月 31 日
The error message says it all.
You're only computing one derivative in my_function. You need to define ys(1) and ys(2), because you refer to y(1) and y(2), and provide two initial conditions. You need to have the same number of derivatives as y values.
  1 件のコメント
Jan
Jan 2013 年 8 月 1 日
+1. Actually all you have answered is a rephrased version of the error message. But you hit the point exactly. The meta-message is a recommendation to read the messages carefully. And especially in the combination with Matlab, this is a very good hint.

サインインしてコメントする。


Francisco Barber
Francisco Barber 2019 年 1 月 21 日
Hello,
I tried defining y(1) and y(2) for a similar program and it continued failing.
Someone found a solution?
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 1 月 21 日
"You need to have the same number of derivatives as y values."

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by