trying to plot a more complicated step function

I need an equation for a function y(t) where; y(t) = 0 from 0 < t < 1.25; y(t) = -0.18 from 1.25 < t < 2.5; y(t) = 0 from 2.5 < t < 7.5;
It's not necessarily a matlab question but I can't figure out how to plot this step function in matlab. One equation would be helpful as opposed to a piecewise function.

回答(1 个)

ts=0.01
t1=0:ts:1.25-ts
t2=1.25:ts:2.5-ts
t3=2.5:ts:7.5
t=[t1 t2 t3]
y=[t1*0 -0.18*ones(size(t2)) 0*t3]
plot(t,y)
or
t=0:ts:7.5
y=-0.18*(heaviside(t-2.5)-heaviside(t-1.5))
plot(t,y)

类别

帮助中心File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by