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

1 view (last 30 days)
MathNemesis on 15 Oct 2021
Commented: MathNemesis on 15 Oct 2021
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 on 15 Oct 2021
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
MathNemesis on 15 Oct 2021
This was exactly it, thanks Paul your the best!

R2020a

### Community Treasure Hunt

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

Start Hunting!