Sie sind auf Seite 1von 4

Math 151a: Applied Numerical Methods

Programming Project 2
1 Goal
For ecological research purposes, a tracking device has been attached to some
individuals on a migratory ock. The goal of this project is to reconstruct
the migration routes used by these birds, by interpolating the signals from the
tracking device.
2 Detailed description
2.1 Method
The device attached to the birds sends information about, among other param-
eters, their position at dierent times:
t
0
x
0
y
0
t
1
x
1
y
1
.
.
.
.
.
.
.
.
.
t
n
x
n
y
n
(1)
The pair (x(t), y(t)) describes a parametric curve corresponding to the path
followed by the member of the ock, that we are interested in. To nd it we
will use polynomial interpolation to get a description of the evolution of the x
and y variables with respect to t, and evaluate it for dierent times in [t
0
, t
n
].
2.1.1 First Approach: Newtons method
One option that we have is to construct a single polynomial that interpolates
all n points, the Lagrange interpolation polynomial. More specically, you
have to code a routine that uses the (forward) divided dierences method to
compute the coecients of the Lagrange polynomial corresponding to a general
set of interpolation points (t
i
, f(t
i
)) and another one that evaluates it using the
Horners method.
Then, a main function that, having the information of the tracking device,
uses the previous routine with the rst two columns (t
i
, x
i
) to nd the Lagrange
interpolation polynomial P
x
n
(t) that for each time t will give us the x coordinate
of the position, and again with the rst and third columns (t
i
, y
i
) to nd the
Lagrange interpolation polynomial P
y
n
(t) that for each time t will give us the y
coordinate.
Once you have the coecients of the polynomials, use the evaluating function
with the points

0
.
.
.

m1
(2)
for both polynomials to get the points in the path.
1
2.1.2 Second approach: Splines
As you can see by plotting the results, sometimes the error is quite large in the
extremes of the interval [t
0
, t
n1
], and grows fast as we increase the number of
points. (See the second question in the implementation part) To handle this,
we can use splines. The spline is a function
S C
2
, S(t) =
_

_
s
0
(t) t [t
0
, t
1
]
.
.
.
.
.
.
s
n2
(t) t [t
n2
, t
n1
]
verifying S(x
i
) = y
i
, i = 0 . . . n 1, S

(x
0
) = y

0
i S

(x
n
) = y

n
, and such that
s
i
:= s
|[xi,xi+1]
is a polynomial of degree 3
s
i
(x) = y
i
+B
i
(x x
i
) +C
i
(x x
i
)
2
+D
i
(x x
i
)
3
. i = 0 n 1, (3)
To nd the values of B
i
, C
i
, D
i
let us denote:
M
i
:= s

(x
i
) and h
i
:= x
i
x
i1
, i = 1 n.
Then
B
i
=
y
i+1
y
i
h
i+1

M
i+1
+ 2M
i
6
h
i+1
, C
i
=
M
i
2
, D
i
=
M
i+1
M
i
6h
i+1
(4)
The values M
i
satisfy the tridiagonal linear system
_
_
_
_
_
_
_
2
0

1
2
1
.
.
.
.
.
.
.
.
.

n1
2
n1

n
2
_
_
_
_
_
_
_
_
_
_
_
_
_
_
M
0
M
1
.
.
.
M
n1
M
n
_
_
_
_
_
_
_
=
_
_
_
_
_
_
_
d
0
d
1
.
.
.
d
n1
d
n
_
_
_
_
_
_
_
,
where for i = 1 n 1,

i
=
h
i+1
h
i
+h
i+1
,
i
= 1
i
=
h
i
h
i
+h
i+1
, d
i
=
6
h
i
+h
i+1
_
y
i+1
y
i
h
i+1

y
i
y
i1
h
i
_
,
and

0
= 1, d
0
=
6
h
1
_
y
1
y
0
h
1
y

0
_
,
n
= 1, d
n
=
6
h
n
_
y

n

y
n
y
n1
h
n
_
.
Again, we want to nd the corresponding splines for the x and y coordinates:
t
0
s
x
0
s
x,0
1
s
x,0
2
s
x,0
3
s
y,0
0
s
y,0
1
s
y,0
2
s
y,0
3
t
1
s
x
0
s
x,1
1
s
x,1
2
s
x,1
3
s
y,1
0
s
y,1
1
s
y,1
2
s
y,1
3
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
t
n
s
x
n
s
x,n
1
s
x,n
2
s
x,n
3
s
y,n
0
s
y,n
1
s
y,n
2
s
y,n
3
(5)
and once we have the coecients, evaluate S
x
and S
y
at the points
0
. . .
m1
to nd the path.
2
2.2 Routines
You have to code:
1. A routine
function [P Control]=divdif(x,y)
that stores the coecients of the Lagrange interpolation polynomial in P.
2. A routine
function [px Control]=evalP(P,x_int, x_test)
that evaluate the the polynomial with coecients stored in P at the point(s)
x and returns that value in px.
3. A routine
function [S Control]=spline3(x,y)
That computes the cubic splines associated to the interpolation points
{(x
i
, y
i
)} and stores them in S.
4. A routine
function [sx Control]=evalS(S,x_int, x_test)
that evaluate the spline with coecients stored in S at the point(s) x and
returns that value in sx.
Control can be used for error verication or testing, or be left empty
(Control=[]); you must decide and specify its use in the guide.
3
3 Summary
You have submit to the ccle page of the course a .zip le containing:
The source les divdif.m, evalP.m, spline3.m, evalS.m of the rou-
tines described above:
A .pdf le with a brief report of the project. The report must include the
following sections:
User Guide: A concise description of all the routines and appli-
cations: what do they do, calling syntax, output format and return
values.
Implementation:
Provide a bound for the maximum error in your approximations,
when we use the Lagrange Interpolation Polynomial and when
we use Splines for the interpolation points provided in the ccle.
Approximate the function f(x) =
1
1+(5x)
2
in the interval [1, 1]
using 10, 30, and 100 interpolation point and compute the max-
imum error associated to each method and comment on the be-
havior of the error as we increase the number of points. Plot
the values of the approximations against the values of the real
function.
Describe the tests done to validate your code, the problems en-
countered, and their solution. You must include at least the tests
proposed in the ccle page of the course.
Solutions: Include the plots of the paths you obtain with the initial
data specied in in the ccle.
4

Das könnte Ihnen auch gefallen