MATLAB, how to input step functions.

In summary, the speaker is struggling with converting an ODE into MATLAB code. They are seeking help in creating a .m file that mimics the step function, and are confused about how to combine different conditions using the elseif statement.
  • #1
btbam91
91
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
  • #2
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
 
  • #3
Doesn't elseif solve the problem you are having?

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

1. What is MATLAB?

MATLAB is a high-level programming language and interactive environment commonly used by scientists and engineers for data analysis, visualization, and mathematical computations.

2. How do I input a step function in MATLAB?

To input a step function in MATLAB, you can use the "heaviside" function, which returns a value of 0 for any input less than 0 and a value of 1 for any input greater than or equal to 0. You can also use the "step" function, which allows you to specify the location and height of the step.

3. What is the syntax for inputting a step function in MATLAB?

The syntax for inputting a step function using the "heaviside" function is "y = heaviside(x)", where "x" is the input value and "y" is the output value. For the "step" function, the syntax is "y = step(x, t)", where "x" is the input value and "t" is a vector specifying the location and height of the step.

4. Can I plot a step function in MATLAB?

Yes, you can plot a step function in MATLAB using the "plot" function. Simply input the step function as the "y" variable and the corresponding input values as the "x" variable. You can also customize the plot by adding a title, labels, and adjusting the axes.

5. Are there any other useful functions for working with step functions in MATLAB?

Yes, there are several other useful functions for working with step functions in MATLAB, such as "ramp" for creating a ramp function, "pulse" for creating a pulse function, and "square" for creating a square wave function. These functions can be used in combination with the "plot" function to create more complex plots and analyze signal data.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
792
  • Engineering and Comp Sci Homework Help
Replies
2
Views
742
  • Engineering and Comp Sci Homework Help
Replies
1
Views
896
  • Engineering and Comp Sci Homework Help
Replies
8
Views
942
  • Engineering and Comp Sci Homework Help
Replies
3
Views
735
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
Replies
23
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
Back
Top