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일

0 개 추천

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

Ljix
Ljix 2016년 2월 3일
Thank you.Can you please explain the dot next to B? Why is that?
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개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

태그

질문:

2016년 2월 3일

댓글:

2016년 2월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by