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
 
I multiplied the values first without the error limit. Got 19.38. rounded it off to 2 significant figures since the given data has 2 significant figures. So = 19. For error I used the above formula. It comes out about 1.48. Now my question is. Should I write the answer as 19±1.5 (rounding 1.48 to 2 significant figures) OR should I write it as 19±1. So in short, should the error have same number of significant figures as the mean value or should it have the same number of decimal places as...
Thread 'A cylinder connected to a hanging mass'
Let's declare that for the cylinder, mass = M = 10 kg Radius = R = 4 m For the wall and the floor, Friction coeff = ##\mu## = 0.5 For the hanging mass, mass = m = 11 kg First, we divide the force according to their respective plane (x and y thing, correct me if I'm wrong) and according to which, cylinder or the hanging mass, they're working on. Force on the hanging mass $$mg - T = ma$$ Force(Cylinder) on y $$N_f + f_w - Mg = 0$$ Force(Cylinder) on x $$T + f_f - N_w = Ma$$ There's also...
Back
Top