Using ODE45 to Solve Matrix Differential Equations in MATLAB

  • Thread starter Thread starter madjid222
  • Start date Start date
  • Tags Tags
    Matlab Ode45
AI Thread Summary
To solve a system of matrix and scalar differential equations using MATLAB's ode45, the matrix variable must be reshaped appropriately. The example provided demonstrates how to set up the matrices A and Q, and how to define the ODE function that incorporates both matrix and scalar equations. The matrix X is reshaped from a column vector back into a 3x3 matrix within the ODE function, and the output dxdt is converted back into a column vector for ode45. The code snippet illustrates the process of defining the time span and plotting the results after solving the equations. Properly handling the dimensions of the variables is crucial for successful implementation.
madjid222
Messages
4
Reaction score
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
I would be grateful if you could possibly help me
 
Kindly see the attached pdf. My attempt to solve it, is in it. I'm wondering if my solution is right. My idea is this: At any point of time, the ball may be assumed to be at an incline which is at an angle of θ(kindly see both the pics in the pdf file). The value of θ will continuously change and so will the value of friction. I'm not able to figure out, why my solution is wrong, if it is wrong .
Thread 'Correct statement about a reservoir with an outlet pipe'
The answer to this question is statements (ii) and (iv) are correct. (i) This is FALSE because the speed of water in the tap is greater than speed at the water surface (ii) I don't even understand this statement. What does the "seal" part have to do with water flowing out? Won't the water still flow out through the tap until the tank is empty whether the reservoir is sealed or not? (iii) In my opinion, this statement would be correct. Increasing the gravitational potential energy of the...
Thread 'A bead-mass oscillatory system problem'
I can't figure out how to find the velocity of the particle at 37 degrees. Basically the bead moves with velocity towards right let's call it v1. The particle moves with some velocity v2. In frame of the bead, the particle is performing circular motion. So v of particle wrt bead would be perpendicular to the string. But how would I find the velocity of particle in ground frame? I tried using vectors to figure it out and the angle is coming out to be extremely long. One equation is by work...
Back
Top