|
"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
|