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

4 visualizaciones (últimos 30 días)
Ljix
Ljix el 3 de Feb. de 2016
Comentada: Star Strider el 5 de Feb. de 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.

Respuesta aceptada

Star Strider
Star Strider el 3 de Feb. de 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 comentarios
Star Strider
Star Strider el 3 de Feb. de 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 el 5 de Feb. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by