
How to solve a set of matrix differential equations given below in Matlab?
6 views (last 30 days)
Show older comments
Sajjan Gundmi Satish
on 14 May 2019
Commented: Star Strider
on 15 May 2019
Consider
for t(0,30)where
C = 1/2 ,
[ 10 2 -5 ;...
2 -10 0 ;...
-5 0 -30 ]
(i am unable to write the matrix using latex editor for some reason, its a 3x3 matrix)
and 
[sin(t) 0 0 ;...
0 1 0 ;...
0 0 cos(t)]
and plot the matrix components y11(t),y12(t), y13(t),y22(t),y23(t) and y33(t)
0 Comments
Accepted Answer
Star Strider
on 15 May 2019
Try this:
y0 = [ 10 2 -5; 2 -10 0; -5 0 -30 ];
C = 0.5;
f = @(t) [sin(t) 0 0 ; 0 1 0 ; 0 0 cos(t)];
t = linspace(0, 30, 75);
for k = 1:numel(t)
y(:,:,k) = (expm(C*t(k))+y0) * f(t(k));
yp(k,:) = [y(1,1,k) y(1,2,k) y(1,3,k) y(2,2,k) y(2,3,k) y(3,3,k)];
end
figure
plot(t, yp)
grid
legend('y_{1,1}', 'y_{1,2}', 'y_{1,3}', 'y_{2,2}', 'y_{2,3}', 'y_{3,3}', 'Location', 'SW')
with:

Experiment to get the result you want.
2 Comments
Star Strider
on 15 May 2019
My code does not compute
. It integrates the differential equation using the matrix exponential function, and plots the result.
This is a linear matrix differential equation. You can certainly use ode45 if you want, however an efficient result is to use the expm function to compute the matrix exponential. (This goes back to the Cayley-Hamilton theorem and functions of a square matrix. Most linear algebra texts and all modern control texts discuss this in some detail.)
You would certainly need ode45 if your differential equations were nonlinear. That does not apply here.
A corrected version of your code (that does not use the entire
matrix) will of course produce a different result:
matrix) will of course produce a different result: fode1 = @(t,y) -1/2*y+sin(t);
y0 = [10 2 -5 2 -10 0 -5 0 -30]';
tspan = [0,30];
C=1/2;
for ii =1:9
[t,y] = ode45(fode1,tspan,y0);
plot(t,y)
end
figure
plot(t,y)
grid
This plots all the results.
I admit that I cannot code your system to use ode45 and use your initial conditions matrix. However this is straightforward using expm.
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations 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!