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:
ODE which is function of 3 variables.

Subject: ODE which is function of 3 variables.

From: Faraz Afzal

Date: 6 Mar, 2009 12:03:06

Message: 1 of 2

Hello all,,

I wish some one could help me with the differential equation of type...

with my codee
m file function is

function dsdt = differential1(t, s , U, A , B , R, P)

dsdt = -A.' *s + U * B * inv(R) * B.' * s + P ; %Determine derivative
 
and in command line it is

[T S] = ode45(@differential1 , [ 0 2], s0 , [] , U, A , B , R, P)

the matrices A, B , R , P are constant
now what should i do if U is changing... it is changing and i have 269 Us and i want to calculate U(1) with s1 at time t1 and U(2) at s2 and t2 and so on... Can any one help......

Take care

Subject: ODE which is function of 3 variables.

From: Steven Lord

Date: 6 Mar, 2009 14:36:48

Message: 2 of 2


"Faraz Afzal" <farazafzal@gmail.com> wrote in message
news:gor3dq$mcj$1@fred.mathworks.com...
> Hello all,,
>
> I wish some one could help me with the differential equation of type...

First, please don't both email me your question and post it on the
newsgroup. Posting it to the newsgroup is enough; I'll see it, as will
others who may answer before I can.

> with my codee
> m file function is
>
> function dsdt = differential1(t, s , U, A , B , R, P)
>
> dsdt = -A.' *s + U * B * inv(R) * B.' * s + P ; %Determine derivative

Don't use INV. Use backslash instead. MLINT should warn you about that,
and I believe it's even one of the options that MLINT can auto-fix if you
ask it to do so.

> and in command line it is
>
> [T S] = ode45(@differential1 , [ 0 2], s0 , [] , U, A , B , R, P)
>
> the matrices A, B , R , P are constant
> now what should i do if U is changing... it is changing and i have 269 Us
> and i want to calculate U(1) with s1 at time t1 and U(2) at s2 and t2 and
> so on... Can any one help......

That may make your ODE function discontinuous. Solve the ODE using smaller
timestep vectors; go from 0 to t1 with the first call to ODE45, using U(1).
Next go from t1 to t2 using U(2) -- you can generate the initial conditions
from the previous call. Repeat until you get to t = 2.

There's an example that does something similar to this -- take a look at the
BALLODE demo. It uses an events function to stop the integration when a
condition is met, but you could do the same thing using the known 'breaks'
in time.

--
Steve Lord
slord@mathworks.com

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