Math245 Computer Lab set #10, Fall 2008
Response to step input
In this lab, we will simulate the 2nd order ODE with discontinuous forcing function. To start with, we
define the step function in Matlab. Then we will simulate an example problem by using the step function
for the forcing function.
The step function
As we learned in the class, the step function
u
(
t
) is defined
u
(
t
) =
(
0
t <
0
1
t
≥
0
(1)
The shifted step function
u
(
t

c
) is expressed
u
(
t

c
) =
(
0
t

c <
0
(
t < c
)
1
t

c
≥
0
(
t
≥
c
)
(2)
1
t
u(tc)
c
1
t
u(t)
Design step function in Matlab
To define the step function
u
(
t
), we create a Matlab function file (
step.m
) as follows.
function y = step(t)
if t < 0
y = 0;
else
y = 1;
end
There are two points to make:
Matlab function
The Matlab
function
is a independent program unit that has a certain function. The simplest form of
the function is written
function out = fun_name(in1, in2,...)
out = some expression using in1, in2, etc.
This function is has its name
fun
name
. And this file should be saved as
fun
name.m
.
in1, in2,...
are
called input arguments, and
out
is called output argument. This function accepts inputs
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 '07
 Alexander
 Math, matlab, Input/output, Step function

Click to edit the document details