Using ODE45 to Solve Matrix Differential Equations in MATLAB

  • Thread starter Thread starter madjid222
  • Start date Start date
  • Tags Tags
    Matlab Ode45
Click For Summary
SUMMARY

This discussion focuses on using MATLAB's ODE45 function to solve matrix differential equations involving both matrix and scalar variables. The specific case presented involves a 3x3 matrix differential equation defined by the equation Pdot = A*P + P*A' + Q, where A and Q are also 3x3 matrices. The solution process includes reshaping the output from ODE45 to match the required matrix dimensions and converting the results back into a column vector format for further analysis.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with ODE45 function in MATLAB
  • Knowledge of matrix operations and linear algebra
  • Experience with reshaping arrays in MATLAB
NEXT STEPS
  • Study the implementation of ODE45 for solving non-linear differential equations in MATLAB
  • Learn about matrix reshaping techniques in MATLAB, specifically using the reshape function
  • Explore the use of matrix exponentials in solving systems of differential equations
  • Investigate advanced plotting techniques in MATLAB for visualizing ODE solutions
USEFUL FOR

Mathematicians, engineers, and students working on differential equations, particularly those utilizing MATLAB for simulations and modeling of dynamic systems involving matrices.

madjid222
Messages
4
Reaction score
0

Homework Statement



If we have differential variable of matrix kind ( with dimension 3*3 ) and non matrix ( with dimension 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
I would be grateful if you could possibly help me
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
8
Views
1K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
9
Views
2K