How to plot values from a for loop?

3 ビュー (過去 30 日間)
Ljix
Ljix 2016 年 2 月 3 日
編集済み: Star Strider 2016 年 2 月 3 日
Maybe my question isn't so specific, but I'll try to explain what's giving me a hard time.
I have to calculate
(C/(s*I-A))*B
where A,B and C are matrices and s is a eigenvalue of some given matrix. I have to calculate it for every eigenvalue and plot it. This is what I did
svA=eig(A);
for P=1:50
fr=(CN/(i*svA(P)*eye(n)-A))*B;
fr_org{P}=fr;
end
fr_original=fr_org{1:50};
plot(fr_original)
but I didn't get anything. Any advice?

回答 (3 件)

Walter Roberson
Walter Roberson 2016 年 2 月 3 日
Try
fr_original = cell2mat(fr_org);
  3 件のコメント
Walter Roberson
Walter Roberson 2016 年 2 月 3 日
plot(fr_original, '*')
Ljix
Ljix 2016 年 2 月 3 日
Now it's working. Thank you.

サインインしてコメントする。


Suresh Garimella
Suresh Garimella 2016 年 2 月 3 日
編集済み: Walter Roberson 2016 年 2 月 3 日
Try this, Hope it works
svA=eig(A);
for P=1:50 fr=(CN/(i*svA(P)*eye(n)-A))*B;
fr_org{P}=fr;
end
%fr_original=fr_org{1:50}; comment this line
fr_original=fr_org; % directly assign
%plot(fr_original) comment this line
plot(cell2mat(fr_original)) % convert class using cell2mat to plot
  1 件のコメント
Ljix
Ljix 2016 年 2 月 3 日
Almost what I want. Using
plot(cell2mat(fr_original),'+') gives what I want.

サインインしてコメントする。


Star Strider
Star Strider 2016 年 2 月 3 日
編集済み: Star Strider 2016 年 2 月 3 日
Actually, this is incorrect:
Y = (C/(s*I-A))*B
The correct expression is:
Y = C*((s*I-A)\B)
that you then invert to create:
y = C*expm(A*t)*B
You cannot do what you want to do in the Laplace domain, especially since s = σ + j*ω. You have to invert it to the time domain to do anything with it.
If you want to do a pole-zero plot, there are functions for that such as pzplot in the Control Systems Toolbox.
  2 件のコメント
Ljix
Ljix 2016 年 2 月 3 日
編集済み: Ljix 2016 年 2 月 3 日
Thank you. Isn't frequency response given by Y = C*((s*I-A)\B), where s=i*ω and ω is eigenvalue of A? How to plot y = C*expm(A*t)*B? 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 日
編集済み: Star Strider 2016 年 2 月 3 日
My pleasure.
In a pole-zero plot, σ is the real part, and is the imaginary part. This becomes equivalent to the Fourier transform if you set σ=0.
If you want the Bode plot (frequency response only, along the σ=0 line), use the transfer function representation of your system created from the core MATLAB ss2tf function, then plot it using the Signal Processing Toolbox freqs function.
EDIT — I Answered your question about y = C*expm(A*t)*B*u in How to plot y = C*expm(A*t)*B?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by