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

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일

1 개 추천

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일

0 개 추천

Hello,
I tried defining y(1) and y(2) for a similar program and it continued failing.
Someone found a solution?

댓글 수: 1

"You need to have the same number of derivatives as y values."

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2013년 7월 31일

댓글:

2019년 1월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by