Using ODE45 to Solve Matrix Differential Equations in MATLAB

In summary, the conversation discusses how to use ode45 when dealing with a combination of differential variables of matrix type and non-matrix type. The solution involves using the m file of ode and the reshape command to convert the matrix into a column vector before solving the equation. The equations used in the example include matrices P, A, and Q, with Pdot being equal to A*P + P*A' + Q. The resulting solution is then plotted using the odefuncare function, which converts the column vector back into a matrix.
  • #1
madjid222
5
0

Homework Statement



If we have differential variable of matrix kind ( with dimention 3*3 ) and non matrix ( with dimention 1) simaltanously and as a couple ,how can we use ode45 ?
If we have only matrix kind , we can use m file of ode at first with the command of reshape (3,3) and then change it to column one.What is the solution in this case ?

Homework Equations


P,A,Q :matrices 3*3
Pdot= A*P +P*A’ +Q
K=P*[1 0 0]
xdot(1) =f(x(1),x(2),x(3)) +k(1)*x(1)
xdot(2)=g(x(1),x(2),x(3)) +k(2)*x(2)
xdot(3)=h(x(1) ,x(2),x(3)) +k(3)*x(3)
x0=[ xa;xb;xc]
P0=x01

The Attempt at a Solution


Example (only matrix differential equation) :
%-----MAIN M-FILE--------------
clear all
%-----VARIABLE SET-UP--------------

A = [0 1 0; 0 0 5; 1 2 3];
Q = [1 0 0; 0 0.5 0; 0 0 0.9];
%-----TO RUN and PLOT ODE SOLUTION--------------
t01= 0;
tf1=30;
tspan1 = LINSPACE(t01, tf1);
X01=zeros(3);
[Time1,X1] = ode45(@(t,X) odefuncare(t,X,A,Q),tspan1,X01);
plot(Time1,X1)
%-------ODEFUNCTION------------------
function dxdt = odefuncare(t,X,A,Q)
X = reshape(X,3,3); %converting X from a column vector generated by ode45 into a 5 x 5 Matrix
dxdt=A*x +x*A’ +Q
dxdt = dxdt(:); %converting dxdt into a column vector as expected by ode45
 
Last edited:
Physics news on Phys.org
  • #2
I would be grateful if you could possibly help me
 

1. What is "Ode45 matlab"?

Ode45 matlab is a built-in function in MATLAB that is used to solve ordinary differential equations (ODEs) numerically. It is a part of the MATLAB ODE suite and uses an efficient method called Runge-Kutta to approximate the solution to an ODE.

2. How do I use "Ode45 matlab"?

To use Ode45 matlab, you will need to define the ODE you want to solve as a function in MATLAB. Then, you can call the Ode45 function and pass in the ODE function, the initial conditions, and the time interval. Ode45 will return the numerical solution to the ODE at the specified time points.

3. What are the advantages of using "Ode45 matlab" over other methods?

Ode45 is a popular choice for solving ODEs because it is efficient, accurate, and versatile. It can handle a wide range of ODEs, including stiff and non-stiff problems, and can adapt its step size to improve accuracy. Additionally, Ode45 is built into MATLAB, making it easily accessible for users.

4. Are there any limitations to using "Ode45 matlab"?

While Ode45 is a powerful tool, it does have some limitations. It is not suitable for solving partial differential equations (PDEs) or systems of ODEs. Additionally, it may not be the best choice for extremely stiff ODEs, as it can be computationally expensive.

5. Can "Ode45 matlab" be used for real-world applications?

Yes, Ode45 is commonly used in engineering, physics, and other scientific fields to solve ODEs that arise in real-world problems. It has been extensively tested and is known for producing accurate results. However, it is always important to verify the results and use caution when applying any numerical method to real-world applications.

Similar threads

  • Introductory Physics Homework Help
Replies
5
Views
3K
  • Introductory Physics Homework Help
Replies
1
Views
983
  • Engineering and Comp Sci Homework Help
Replies
1
Views
865
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
869
Back
Top