stair function - how to
Hi experts!
How can I make a stair function graph?
Thanks a lot!
You can use a sum of heaviside
functions.
f(x)=heaviside(x)+heaviside(x-1)+heaviside(x-2)+heaviside(x-3)
plot(f(x),(x,0,4),exclude=[0,1,2,3])
Or, you can do it with a python function.
def step(x):
if (0<x) and (x<1):
return(1)
elif (x<2):
return(2)
elif (x<3):
return(3)
else:
return(4)
plot(lambda x: step(x),(x,0,4),exclude=[0,1,2,3])
You could also use the piecewise
command.
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 11 years ago
Seen: 1,095 times
Last updated: Oct 18 '13