plotting an exponential will a matrix over time
이전 댓글 표시
Hi guys, i want to plot Y respect to time in 40 seconds. AF is a 4x4 matrix,
t= [0:2:40];
iden= eye(4);
AF= [ 0 1 0 0; 0.00010714 0.00275 10.049 0.98385; 0 0 0 1; -7.6531e-05 -0.0019643 -0.17761 -0.70275];
meme=iden*AF;
figure(1)
Y = exp(AF.*meme);
plot(t,Y);
It results in vector must be in the same length, i do not know how to fix it.
댓글 수: 3
Image Analyst
2019년 4월 13일
t= [0:2:40]
iden= eye(4)
AF= [ 0 1 0 0;
0.00010714 0.00275 10.049 0.98385;
0 0 0 1;
-7.6531e-05 -0.0019643 -0.17761 -0.70275]
meme=iden*AF
figure(1)
Y = exp(AF.*meme)
plot(t,Y);
t =
Columns 1 through 20
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38
Column 21
40
iden =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
AF =
0 1.0000 0 0
0.0001 0.0027 10.0490 0.9839
0 0 0 1.0000
-0.0001 -0.0020 -0.1776 -0.7027
meme =
0 1.0000 0 0
0.0001 0.0027 10.0490 0.9839
0 0 0 1.0000
-0.0001 -0.0020 -0.1776 -0.7027
Y =
1.0e+43 *
0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 7.1796 0.0000
0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000
t is a 1-by-20 array, and Y is a 4-by-4 array, so exactly what do you want to plot?
IP KWAN SO
2019년 4월 13일
Vineeth Nair
2019년 4월 18일
The matrix dimensions must agree before multiplication can happen. Hence the above expression Y= exp(AF.*t) is incorrect.
To read more about elementwise multiplication please visty this link https://in.mathworks.com/help/matlab/ref/times.html
답변 (1개)
David Wilson
2019년 4월 18일
편집: David Wilson
2019년 4월 18일
OK, your question is a bit vauge, and there are missing bits, i.e. the start point for y.
I'm assuming you are trying to solve a control problem. As mentioned above, you need to carefully look at dimensions, and I think you want the matrix exponental function, expm, (don't forget the "m").
I started my simulation below at some random point.
t= [0:2:40]; % time vector
AF= [ 0 1 0 0;
0.00010714 0.00275 10.049 0.98385;
0 0 0 1;
-7.6531e-05 -0.0019643 -0.17761 -0.70275];
Y = randn(1,4); % start position (who knows??)
for i=2:length(t)
Y(i,:) = expm(AF*t(i))*Y(i-1,:)';
end
plot(t,Y);
Of course if you have the control toolbox, there are many better ways to do this, e.g.
>> help lti/initial
or,
G = ss(AF, zeros(4,1), eye(4,4), 0)
Y0 = randn(1,4); % another random start poit
[Y,t] = initial(G,Y0,t) % simulate the free response
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!