MATLAB, how to input step functions.

AI Thread Summary
To input step functions in MATLAB for the given ODE y' = -a*y + u(t-1) - u(t-3), users can utilize conditional statements to define the step functions. The Heaviside function can be helpful, as indicated by suggestions to type "help heaviside" for guidance. Combining the step functions into a single .m file can be achieved using nested if-else statements to represent the conditions for t. The discussion emphasizes the importance of understanding how to structure these conditions effectively. Overall, the thread provides insights into handling step functions in MATLAB for solving differential equations.
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
 

Similar threads

Back
Top