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.
0 个评论
采纳的回答
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
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!