train dynamics undefined variable and ode problem

1 回表示 (過去 30 日間)
sarngon
sarngon 2012 年 1 月 25 日
hello,
i need help about ode23 and subfunction topic
function xdot=train(t,x) alfa=0.3; beta=0.13; gama=0.16; Ua=1; Ub=2; xdot=[x(2);((2/pi)*(atan((x-4)/0.05)+atan((x-2)/0.05))-alfa-beta*abs(x(2))-gama*(x(2)^2)+Ua-Ub)];
end
and the plot function
[t,x]=ode23('train',[0,0.1],[0;0]); subplot(2,1,1);plot(t,x(:,1)) subplot(2,1,2); plot(t,x(:,2))
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
and the error is
??? Error using ==> odearguments at 116 TRAIN returns a vector of length 3, but the length of initial conditions vector is 2. The vector returned by TRAIN and the initial conditions vector must have the same number of elements.
Error in ==> ode23 at 172 [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in ==> main1 at 1 [t,x]=ode23('train',[0,0.1],[0;0]);
THANKS FOR YOUR HELP.....
  2 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 25 日
As an editor on this site, I normally leave terms such as "urgent" in place for tracking purposes. Your title term of "Emergency" was beyond my tolerance and I have removed it.
If you post that something is an "emergency" then you should be able to document that there was a literal and immediate risk of loss of life, or at least of serious and literal risk of damage to health (e.g., a broken leg.) If emergency officials such as ambulance or fire department or police or doctors did not get involved, then it was probably NOT an emergency.
sarngon
sarngon 2012 年 1 月 25 日
sorrry

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

回答 (3 件)

Walter Roberson
Walter Roberson 2012 年 1 月 25 日
Your expression for xdot has two atan() calls with arguments that are expressions in x -- but x is a vector, so you get out a vector result the same length as x... but you also put x(2) at the front of that vector, resulting in a vector of length 3.
  1 件のコメント
sarngon
sarngon 2012 年 1 月 26 日
Hi can u help me pls i added a message to my ouestion
thanks

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


sarngon
sarngon 2012 年 1 月 26 日
ok i change the matrix variable name as k(2)and kdot but now the prog gives such a error
codes function kdot=train(t,x) alfa=0.3; beta=0.13; gama=0.16; Ua=1; Ub=2; kdot=[k(2);(2/pi)*(atan((x-4)/0.05)+atan((x-2)/0.05))-(alfa+beta*abs(k(2))+gama*(k(2)^2))+Ua-Ub];
end
and the error line
??? Undefined function or method 'k' for input arguments of type 'double'.
Error in ==> train at 7 kdot=[k(2);(2/pi)*(atan((x-4)/0.05)+atan((x-2)/0.05))-(alfa+beta*abs(k(2))+gama*(k(2)^2))+Ua-Ub];
thanks..
  3 件のコメント
sarngon
sarngon 2012 年 1 月 26 日
yeah i found thanks for your help.. there i must use atan(x(1)) instead of atan(x)
Walter Roberson
Walter Roberson 2012 年 1 月 26 日
The Question is solved then?

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


devalaraju venkata naga amulya
devalaraju venkata naga amulya 2021 年 2 月 23 日
Hello I want to know that how to know the ode's in a vehicle train model. we can calculate manually if the degrees of freedom is small like 5,10 . but what is it is lie 41DOF and more than that . is there any possible approach in matlab to directly code a script and get to know the equations for the system by coding anything in matlab. kindly help and suggest anything in this regard.
thank you in advance

カテゴリ

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