필터 지우기
필터 지우기

How to pass values from one ode to another ode?

조회 수: 1 (최근 30일)
Deepana
Deepana 2013년 2월 10일
I av to use the results of one ode(ode45) inside another ode... here is my code:
1st ode function
function dw=sd(t,w)
va=10;
vb=0;vc=0;
%MOMENT OF INERTIA IN PRINCIPAL AXIS
I1=27;
I2=17;
I3=25;
%DIFFERENTIAL EQUATIONS
dw(1,1)= ((I2-I3)/I1)*w(2)*w(3)+(va/I1);
dw(2,1)=((I3-I1)/I2)*w(1)*w(3)+(vb/I2);
dw(3,1)=((I1-I2)/I3)*w(1)*w(2)+(vc/I3);
function cal
[t,W]=ode45('sd',[tinit tfinal],[0;0;0]);
i av use the results of these in another ode function below
function dq=sk(t,q,w1,w2,w3)
dq(1,1)=0.5*(w3*q(2)-w2*q(3)+w1*q(4));
dq(2,1)=0.5*(-w3*q(1)+w1*q(3)+w2*q(4));
dq(3,1)=0.5*(w2*q(1)-w1*q(2)+w3*q(4));
dq(4,1)=0.5*(-w1*q(1)-w2*q(2)+w3*q(3));
end
function cal
[t,Q]=ode45('sk',[tinit tfinal],[0;1;0;0],W(:,1),W(:,2),W(:,3))
there s some error in passing as shown aabove
any suggestion pl?

답변 (2개)

ChristianW
ChristianW 2013년 2월 10일
Write all equations in 1 function and make your state vector like this: 'x = [w;q]'. Tell me, if you need more details.

the cyclist
the cyclist 2013년 2월 10일
When you call ode45() the second time, with the function 'sk', you are calling it with 4 input arguments, but I don't think you've got the input structure correct.
If you run your code after first having done
>> dbstop if error
you will see that your W(:,1) vector is being interpreted by ode45() as the options input.
  댓글 수: 1
Deepana
Deepana 2013년 2월 16일
Yes i rectified those mistakes.Thanku.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by