How to solve a set of matrix differential equations given below in Matlab?

6 views (last 30 days)
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)

Accepted Answer

Star Strider
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:
How to solve a set of matrix differential equations given below in Matlab - 2019 05 15.png
Experiment to get the result you want.
  2 Comments
Sajjan Gundmi Satish
Sajjan Gundmi Satish on 15 May 2019
How is this computing the dy/dt ? Wouldn't it require ode function?
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(ii));
figure(ii)
plot(t,y)
end
function dy = fode1(t,y)
C = 1/2;
% f = [sin(t) 0 0 0 1 0 0 0 cos(t)]';
dy = -C*y+sin(t);
The above gives me all the y values but only at the first f(t).
How should i go about it for all the values of f(t)?
Star Strider
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:
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.

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!