MATLAB, how to input step functions.

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 6K views
btbam91
Messages
91
Reaction score
0
Hey guys, I am extremely inexperienced with MATLAB and I"m struggling putting this ode into matlab.

y' = -a*y+u(t-1)-u(t-3)

I know that for y=u(t-1), you type:

if t<1
y=0;
else
y=1;
end

and for y=u(t-3):
if t<3
y=0;
else
y=1;

But I'm confused as to how you'd combine all of the above into a correction function m file!

Thanks!
 
Physics news on Phys.org
I am trying to understand your question here. Is your question you'd like to have a .m file that mimics the step function? type "help heaviside" see if that helps
 
Doesn't elseif solve the problem you are having?

if condition1
then something
elseif condition2
then something else
...
...
...
else
something
end