How to plot y = C*expm(A*t)*B?

1 view (last 30 days)
Ljix
Ljix on 3 Feb 2016
Commented: Star Strider on 5 Feb 2016
How to plot y = C*expm(A*t)*B, where A,B and C are matrices? I tried defining t=linspace(0,100,25) and then calculate y as function (as defined) and I got message about dimension error.

Accepted Answer

Star Strider
Star Strider on 3 Feb 2016
This works:
A = [1 -4; 3 -5]; % Define System Matrices
B = [1; 1];
C = [1 0; 0 1];
N = 50; % Length Of Simulation (Samples)
t = linspace(0, 5, N); % Time Vector
u = ones(2, N); % System Input
for k1 = 1:length(t);
y(:,k1) = C*expm(A*t(k1))*B.*u(:,k1); % Evaluate System At Each Time & Input
end
figure(1)
plot(t, y)
grid
  3 Comments
Star Strider
Star Strider on 3 Feb 2016
The dot is an operator that converts the matrix multiplication operator (*) to an element-wise operator (.*). See the documentation for Array vs. Matrix Operations for a fun and interesting time!
Star Strider
Star Strider on 5 Feb 2016
The (1x2) vector for ‘C’ should work, because the other matrices are (2x2). It would then produce a column-vector output.
The problem is with ‘u=ones(1,N)’. The ‘u’ vector has to have two rows at any time (or equivalently, index) to work in my example, although they do not have to be all 1. The ‘u’ is the input to the dynamical system, so it can have any value, providing that every column presented to the system as an input has two rows. That is likely where the dimension error originates.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!