How to plot several unit steps in a graph without doing it manually?

조회 수: 3 (최근 30일)
MathNemesis
MathNemesis 2021년 10월 15일
댓글: MathNemesis 2021년 10월 15일
Hello!
So im currently having some problems with plotting. I have a function that produces my step answer, I now want to plot the results from the function. I have tried done it manually, for example like having it in this form:
y_4 = y_step_4(t);
y_8 = y_step_8(t);
y_53 = y_step_53(t);
hold on;
plot(t,y_4)
plot(t,y_8)
hold off;
function y = y_step4(t)
y = 1 - 2.t*.exp(.2.t);
end
function y = y_step8(t) etc etc
However, this is not a good approach, how would be a better approach to reduce the tedious work of manually plotting it?
This is currently how the code looks like:
%Creates a unit step
create_y_step(4)
function H = transferH(K)
syms s;
% Declaring transfer function G(s)
G = 1/(s*(s+4));
H = (G*K)/(1+G*K);
end
function y = create_y_step(K)
syms s t
H = transferH(K);
y = ilaplace(H*(1/s)); %Unit step
end
%syms t s K
% G = 1/(s*(s+4))
% H = (G*K)/(1+G*K)
% y_step = ilaplace(H*1/s)
All answers and help is greatly appreciated!

채택된 답변

Paul
Paul 2021년 10월 15일
Are you looking for something like this?
y2 = create_y_step(2)
y2 = 
y4 = create_y_step(4)
y4 = 
y8 = create_y_step(8)
y8 = 
fplot([y2 y4 y8],[0 10])
legend("y2","y4","y8")
function H = transferH(K)
syms s;
% Declaring transfer function G(s)
G = 1/(s*(s+4));
H = (G*K)/(1+G*K);
end
function y = create_y_step(K)
syms s t
H = transferH(K);
y = ilaplace(H*(1/s)); %Unit step
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by