how to give initial condition as array in ode45

I want to enter initial condition of 6x6 matrix in ode45.
How to do that? Any idea.
Please help

2 Comments

Sir, how do i solve an ode with an array , using ode45? ODE is udY/dx=P, Y,P are arrays.
@DIP: Please do not attach a new question to an existing thread. Thanks.

Sign in to comment.

 Accepted Answer

The ode45 initial conditions have to be a vector.
You have my interest, though. Why do you want them to be a matrix?

10 Comments

In my program, I have one differential equation of say : Hdot= something.
Now size od Hdot is 6x6
So i have to give initial condition of 6x6
I want use it in Kalman Filter equation.
No, you don’t need a matrix of initial conditions.
You need a (6x1) vector of initial conditions, since you have a system of 6 differential equations, each an expression for the derivative of one of your variables.
The vector should work.
EDIT — I’ll have to go back to my Kalman filter books to understand what you might be doing (too tired tonight), but what I mentioned about the initial condition vector for ode45 is correct.
If I send you the code is, it possible to rectify the error?
Please help me.
Pdot = F * P + P * F' + Q - P * H' *inv® * H * P;
Here P dot is a 6x6 matrix. Yes it is diagonal matrix. Still I dont know how to enter the initial condition.
Ok take rest.
Thanks for immediate reply. Good night
Don’t send it to me, instead post it as an attachment to your original Question (use the ‘paper-clip’ icon in the toolbar above the window). That way, if I can’t answer it, there are others here on MATLAB Answers who probably can, and will be able to read and run your code. If you send it only to me, others will not have access to it.
I don’t know exactly what the initial conditions for your system are, but a vector of zeros will likely work unless you know they will not. If you have a function file or anonymous function for Pdot, call ode45 this way:
% For a function file for |Pdot| named |Pdot.m|:
[T, P] = ode45(@Pdot, tspan, zeros(6,1));
% For an anonymous function such as:
F = [matrix];
P = [matrix];
Q = [matrix];
R = [matrix];
H = [matrix];
Pdot = (t,p,F,P,Q,R,H) F * P + P * F' + Q - P * H' * R \ H * P;
[T, P] = ode45(@(t,p) Pdot(t,p,F,P,Q,R,H), tspan, zeros(6,1));
You will have to define F, P, Q, R, H. I cannot test this code because I do not have all your information. However, it should work. (Note that I replaced inv( R ) * H by R \ H. That is more efficient and will produce a more accurate result.)
Respected Star Thank you very much!
I thought I took much time of your rest.
Well I have Pdot equation as one of the two more differential equations.
What I did is that as you said : I put initial condition of 6 variables (diagonal) of P initial matrix. And then inside program, I equated them in for loop with eye(y).
Any way your help and attitude to help is simply great.
In gratitude Abhijit
My pleasure!
I am happy it worked.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!