MATH 573 ASSIGNMENT 8
Before beginning the problems in this assignment, copy the following ﬁles from the web
page
http://www.math.rutgers.edu/~falk/math573/matlabprog.html
to your home di
rectory. The use of these ﬁles will greatly simplify these problems.
euler.m
This ﬁle contains the function
euler(FunFcn,tspan,y0,n)
that takes as inputs
the name of a function enclosed in quotes (e.g., ’ocnfcn’) which is the right hand side of
the diﬀerential equation, a vector
tspan = [t0, tﬁnal]
of the initial and ﬁnal times, the
initial condition
y0
(it must be a column vector), and the number of subintervals
n
. The
output is
[t,y]
, where
t
is a column vector containing the times
t
0+
h, .
. . , tfinal
at which the
approximate solution is computed and
y
is a matrix whose ith row contains an approximation
to the solution [
y
1
(
t
0+
i h
)
, y
2
(
t
0+
i h
)
, . . . , y
m
(
t
0+
i h
)], where
m
is the number of components
in the vector
y0
. It implements Euler’s method with constant step size
h
= (
tfinal

t
0)
/n
.
rk2.m
This ﬁle contains the function
rk2(FunFcn,tspan,y0,n)
which has the same
inputs and outputs as Euler’s method. It implements Heun’s method with constant step size
h
= (
tfinal

t
0)
/n
.
ocfcn.m
This ﬁle contains the function
ocnfcn(t,y)
which takes as inputs a value of
t
and a column vector
y
and returns a column vector given by the function
F(t,y)
which is
the right hand side of the diﬀerential equation
y
0
(
t
) =
F
(
t, y
). In this function,
y
and
F
are
scalar functions with
F
= 1

2
ty
.
vdpfcn1.m