trying to loop for transfer function plots into single figure

Parameters========================
Km1 = 0.01;
Km2 = 0.02257;
Km3 = 0.04;
Rm = 2.093;
b = 0.0000262;
t = 0.069;
T=0:0.0001:4;
========================================
something I tried, but It didnt work
for i :1:3
K(i) = Km(i)/(Rm*b+Km(i)^2);
oltf(i)=tf([K(i)],[t,(i)]);
step(i)=step(oltf(i),T);
plot(T, step(i),'r');
end
trying to fit all three plots into one figure
Thank you!!

1 件のコメント

VINAYAK LUHA
VINAYAK LUHA 2023 年 9 月 7 日
編集済み: VINAYAK LUHA 2023 年 9 月 7 日
The "hold on" command may help, find its documentation in the following link https://in.mathworks.com/help/matlab/ref/hold.html

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

 採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 9 月 7 日
編集済み: Dyuman Joshi 2023 年 9 月 7 日
%Do not name variables dynamically
%defining them in an array and using indexing is a much better option
Km = [0.01 0.02257 0.04];
Rm = 2.093;
b = 0.0000262;
t = 0.069;
T = 0:0.0001:4;
%Defining K via vectorization
K = Km./(Rm.*b+Km.^2);
%Initialise a figure and use hold on to retain plots on the same axes
figure
hold on
for i =1:3
oltf = tf([K(i)],[t,(i)]);
step(oltf,T)
%%It's not a good idea to use function names as variables names
%step(i)=step(oltf(i),T);
%%No need to use the plot command, as the step command itself outputs a plot
%plot(T, st(i),'r')
end
hold off

4 件のコメント

Young Lee
Young Lee 2023 年 9 月 7 日
There is a problem with this solution that the K (aplitude is not reflecting to the actual) eg
K@(0.02257) = Km./(Rm.*b+Km.^2) = 0.02257 / (2.093 *0.0000262 + 0.02257^2 ) = 40 ( but on the actual response from the plot the gain is at only half of it (20)
can you see the problem>?
@Dyuman Joshi didn't make any mistakes in the code because he merely duplicated the transfer function from your original code. However, based on your screenshot, I would like to suggest that the correct transfer function should be:
It's perfectly fine to notify him about the issue you had.
Km1 = 0.01;
Km2 = 0.02257;
Km3 = 0.04;
Km = [Km1 Km2 Km3];
Rm = 2.093;
b = 0.0000262;
t = 0.069;
T = 0:0.0001:4;
for i = 1:3
K = Km(i)/(Rm*b + Km(i)^2);
den = [t, 1]; % <-- fix denominator here
oltf = tf(K, den);
step(oltf, T), hold on
end
grid on
hold off
Young Lee
Young Lee 2023 年 9 月 8 日
thanks for your kind help
Sam Chak
Sam Chak 2023 年 9 月 8 日
@Young Lee, You are welcome!

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by