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

3 次查看(过去 30 天)
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.

采纳的回答

Star Strider
Star Strider 2016-2-3
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 个评论
Star Strider
Star Strider 2016-2-3
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 2016-2-5
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by