Why I'm keep getting these errors? Please help!
12 次查看(过去 30 天)
显示 更早的评论
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])
0 个评论
回答(2 个)
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
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
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!