Math245 Computer Lab set #3, Spring 2009
Inline funtion
Suppose now we have a function that we are interesting in how it looks like, for example,
y
=
exp
(

x/
5)
cos
(
x
2
)

1
(1)
Step one – create a handle called
f
to represent this function, i.e.,
f
= @(
x
)
exp
(

x/
5)
*
cos
(
x
2
)

1
(2)
Step two – use function
ezplot
to get a quick look,
ezplot
(
f,
0
,
8)
(3)
0
1
2
3
4
5
6
7
8
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
x
exp(x/5) cos(x
2
) 1
In step one, the handle’s name
f
is free to be changed to anything you like, but the format = @(
x
) has
to be there. In other words, if it is a function of two variables, the format should be = @(
x, y
) in the
case that the two variables are
x
and
y
. Notice that in describing the function, there is no need to use
elementbyelement operators, i.e., (
.
*
, etc.
) Also notice that the handle
f
is stored as a variable therefore
a
clear
command will remove this handle.
Solve the 1st order ODE by using Matlab
We consider the 1st order ODE in the form
dy
dt
=
f
(
t, y
)
,
with initial condition
y
(0) =
y
0
. To obtain the numerical solution to this initial value problem, we will
use ODE solver
ode45
(RungeKutta 45th order method) in Matlab package. The simplest use of
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.
 Spring '07
 Alexander
 Math, Boundary value problem, @, 1st order ODE, @odefun

Click to edit the document details