Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
using ode45 to solve coupled differential eqns

Subject: using ode45 to solve coupled differential eqns

From: Windell

Date: 18 Nov, 2009 12:46:04

Message: 1 of 7

Hi,

I have two first order differential equations that are coupled to each other and each of them use matrices. I have found many examples that solve a system of ODEs using ode45, however I have not found an example that solves a system of linear algebra differential equations.

Any suggestions?

Thank you very much,
Windell

Subject: using ode45 to solve coupled differential eqns

From: Steven Lord

Date: 18 Nov, 2009 14:35:42

Message: 2 of 7


"Windell " <windelljones@gmail.com> wrote in message
news:he0qac$66t$1@fred.mathworks.com...
> Hi,
>
> I have two first order differential equations that are coupled to each
> other and each of them use matrices. I have found many examples that solve
> a system of ODEs using ode45, however I have not found an example that
> solves a system of linear algebra differential equations.
>
> Any suggestions?

So you have a system like:

y' = M*y

for an appropriately-sized M matrix?

Just write your ODE function so that it computes M*y and returns the result,
then call ODE45 on that function.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: using ode45 to solve coupled differential eqns

From: Windell

Date: 19 Nov, 2009 02:15:10

Message: 3 of 7

"Steven Lord" <slord@mathworks.com> wrote in message <he10lr$aqs$1@fred.mathworks.com>...
>
> "Windell " <windelljones@gmail.com> wrote in message
> news:he0qac$66t$1@fred.mathworks.com...
> > Hi,
> >
> > I have two first order differential equations that are coupled to each
> > other and each of them use matrices. I have found many examples that solve
> > a system of ODEs using ode45, however I have not found an example that
> > solves a system of linear algebra differential equations.
> >
> > Any suggestions?
>
> So you have a system like:
>
> y' = M*y
>
> for an appropriately-sized M matrix?

Actually, I'm sorry stephen, I was wrong.
My system looks like this...
y'=M*x
x'=N*x

sorry for the confusion. Does this change the problem much?
>
> Just write your ODE function so that it computes M*y and returns the result,
> then call ODE45 on that function.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Subject: using ode45 to solve coupled differential eqns

From: Windell

Date: 19 Nov, 2009 02:28:03

Message: 4 of 7

Let me restate that.

My system is
y'=y'(y,x)
x'=x'(x,y)

where x',y' are the derivatives of the vectors x and y respectively.

"Windell " <windelljones@gmail.com> wrote in message <he29ne$k0v$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <he10lr$aqs$1@fred.mathworks.com>...
> >
> > "Windell " <windelljones@gmail.com> wrote in message
> > news:he0qac$66t$1@fred.mathworks.com...
> > > Hi,
> > >
> > > I have two first order differential equations that are coupled to each
> > > other and each of them use matrices. I have found many examples that solve
> > > a system of ODEs using ode45, however I have not found an example that
> > > solves a system of linear algebra differential equations.
> > >
> > > Any suggestions?
> >
> > So you have a system like:
> >
> > y' = M*y
> >
> > for an appropriately-sized M matrix?
>
> Actually, I'm sorry stephen, I was wrong.
> My system looks like this...
> y'=M*x
> x'=N*x
>
> sorry for the confusion. Does this change the problem much?
> >
> > Just write your ODE function so that it computes M*y and returns the result,
> > then call ODE45 on that function.
> >
> > --
> > Steve Lord
> > slord@mathworks.com
> > comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> >

Subject: using ode45 to solve coupled differential eqns

From: Steven Lord

Date: 19 Nov, 2009 03:20:22

Message: 5 of 7


"Windell " <windelljones@gmail.com> wrote in message
news:he2afj$5ua$1@fred.mathworks.com...
> Let me restate that.
>
> My system is
> y'=y'(y,x)
> x'=x'(x,y)
>
> where x',y' are the derivatives of the vectors x and y respectively.

Let z = [x; y] and adapt your y(y, x) and x(y, x) to use the z vector
instead of the y and x vectors individually.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: using ode45 to solve coupled differential eqns

From: Windell

Date: 19 Nov, 2009 04:19:19

Message: 6 of 7

Sorry Steven, I'm not sure what you mean. Would you elaborate please? Here is what my code looks like with the equations.

function x=diff_eqs(t,[Omega_BI Gamma])
%define needed unit vectors.
e1=[1 0 0];
e3=[0 0 1];
%create skew symmetric matrix of e3 unit vector.
e3cross=[0 -1 0;1 0 0;0 0 0];
%satellite intertial matrix. (kg-m^2)
J=eye(3,3)*6.667*10^-3;
%satellite orbital angular velocity (rad/s)
Omega_L=1.1636*10^-3;
%define initial orientation of satellite in orbit wrt
%intertial coordinate frame
R_0=eye(3,3);
%initialize the solution vectors to zero.
x=zeros(2,1);
%define a positive scalar kp.
k_p=5;


%define the diff equations.
R_LI=R_0*exp(Omega_L*e3cross*t);
Omega=R_LI*(Omega_BI-Omega_L*e3);
u=-k_p*R_LI'*(cross(Gamma,e1)+Omega)-Omega_L*(cross(J*Omega_BI,cross(e3));
dotOmega_BI= inv(J)*(cross(J*Omega_BI,Omega_BI)+ u);
dotGamma=cross(Gamma,R_LI*(Omega_BI-Omega_L*e3));




"Steven Lord" <slord@mathworks.com> wrote in message <he2dfi$4p7$1@fred.mathworks.com>...
>
> "Windell " <windelljones@gmail.com> wrote in message
> news:he2afj$5ua$1@fred.mathworks.com...
> > Let me restate that.
> >
> > My system is
> > y'=y'(y,x)
> > x'=x'(x,y)
> >
> > where x',y' are the derivatives of the vectors x and y respectively.
>
> Let z = [x; y] and adapt your y(y, x) and x(y, x) to use the z vector
> instead of the y and x vectors individually.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Subject: using ode45 to solve coupled differential eqns

From: Steven Lord

Date: 19 Nov, 2009 14:57:45

Message: 7 of 7


"Windell " <windelljones@gmail.com> wrote in message
news:he2h07$6vn$1@fred.mathworks.com...
> Sorry Steven, I'm not sure what you mean. Would you elaborate please? Here
> is what my code looks like with the equations.

You have function f(y, x) and g(y, x) such that:

y' = f(y, x)
x' = g(y, x)

If you let z = [y; x] then:

z' = [y'; x'] = [f(y, x); g(y, x)]

So write a function that accepts t and z, just like any regular ODE
function, and computes [f(y, x); g(y, x)] using t and z. You may need to
pass into that function an additional input argument that indicates how many
elements of z 'belong' to y so your ODE function can call f(y, x) and g(y,
x) correctly.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us