Você está na página 1de 21

red red red red red red red red red red red red red red red

red red red red red red red red red red
MT 2106: Numerical Analysis - Dierentiation
John Ngubiri
1
& Nasser Kimbugwe
2
ngubiri@cis.mak.ac.ug, nkimbugwe@cis.mak.ac.ug
Makerere University
College of Computing and Information Sciences
2013/2014 Sem II
1
BSc Computer Science
2
BSc Software Engineering
John & Nasser redMT 2106
Numerical Analysis Numerical Dierentiation
Numerical Dierentiation
Given a function
y = f (x); y = x
2
Dierentiating gives:
dy
dx
= 2x
Evaluating this at x = 1, gives:
dy
dx
= 2
John & Nasser (CoCIS) MT 2106 2014 2 / 21
Numerical Analysis Numerical Dierentiation
Numerical Dierentiation
Numerical dierentiation goes from the function y = x
2
to the value
2, without actually dierentiating (there is no need to know the
equation of a function)
The procedure involves replacing the exact relation by the best
approximating or interpolating polynomial, say, y = (x)
The interpolation formula to be used depends on the value of x at
which the derivative is required
John & Nasser (CoCIS) MT 2106 2014 3 / 21
Numerical Analysis Numerical Dierentiation
Why Numerical Dierentiation?
If the data is from an experiment, the only choice for a derivative is a
numerical technique
The equation relating y and x may not known, but contained in a
table, e.g.,
x x
0
x
1
... x
n
y y
0
y
1
... y
n
If y = f (x) is known but is not trivial to nd f

(x), a numerical
technique can be used to approximate f

(x)
John & Nasser (CoCIS) MT 2106 2014 4 / 21
Numerical Analysis Numerical Dierentiation
Numerical Dierentiation
If the values of x are equally spaced and
dy
dx
is required near the
beginning of the table, Newtons Forward Dierence formula is used
If required near end of table, use Newtons Backward Dierence
formula
If the values are not equispaced, use Lagranges or Newtons Divided
Dierence formulae to represent the functions
John & Nasser (CoCIS) MT 2106 2014 5 / 21
Numerical Analysis Numerical Dierentiation
Derivatives Using NFFDIP
Consider the Forward Interpolating polynomial:
y
n
(x) = y
0
+ py
0
+
p(p 1)
2!

2
y
0
+
p(p 1)(p 2)
3!

3
y
0
+ ...
+
p(p 1)(p 2)...(p (n + 1))
n!

n
y
0
(1)
where p =
xx
0
h
John & Nasser (CoCIS) MT 2106 2014 6 / 21
Numerical Analysis Numerical Dierentiation
Derivatives Using NFFDIP
This can be written as:
y
n
(x) = y
0
+ py
0
+
(p
2
p)
2

2
y
0
+
(p
3
3p
2
+ 2p)
6

3
y
0
+
(p
4
6p
3
+ 11p
2
6p)
24

4
y
0
+ .... (2)
John & Nasser (CoCIS) MT 2106 2014 7 / 21
Numerical Analysis Numerical Dierentiation
Derivatives Using NFFDIP
Dierentiating eqn (2) w.r.t x gives:
Using the chain rule:
dy
dx
=
dy
dp

dp
dx
But
x = x
0
+ ph
dx
dp
= h and
dp
dx
=
1
h
John & Nasser (CoCIS) MT 2106 2014 8 / 21
Numerical Analysis Numerical Dierentiation
Derivatives Using NFFDIP
dy
dx
=
dy
dp

1
h
dy
dx
= [y
0
+
(2p 1)
2

2
y
0
+
(3p
2
6p + 2)
6

3
y
0
+
(4p
3
18p
2
+ 22p 6)
24

4
y
0
+ ....]
1
h
(3)
John & Nasser (CoCIS) MT 2106 2014 9 / 21
Numerical Analysis Numerical Dierentiation
Derivatives Using NFFDIP
Eqn (3) is handy for computing
dy
dx
for non-tabular values of x
For example,
x x
0
x
1
... x
n
y y
0
y
1
... y
n
To nd
dy
dx
at x = i , where x
i
(x
0
, x
1
) or (x
1
, x
2
), etc, but not any of
x
1
, x
2
, ..., x
n
(end points not included in the interval), then eqn (3) can be
used
John & Nasser (CoCIS) MT 2106 2014 10 / 21
Numerical Analysis Numerical Dierentiation
Derivatives Using NFFDIP
To nd the derivative
dy
dx
at x = x
0
(and the other end points in given
range), with
p =
(x x
0
)
h
=
(x
0
x
0
)
h
= 0
Substituting p = 0 in eqn (3) gives:
dy
dx
=
1
h
[y
0

1
2

2
y
0
+
1
3

3
y
0

1
4

4
y
0
+ ....] (4)
Eqn (4) is used to compute
dy
dx
at any of the interpolating points - by
setting x
0
to be equal to the interpolating point (most suitable at the
beginning of the table)
John & Nasser (CoCIS) MT 2106 2014 11 / 21
Numerical Analysis Numerical Dierentiation
Example
Find
dy
dx
at x = 1, x = 0 from:
x 0 2 4 6 8
y 7 13 43 145 367
John & Nasser (CoCIS) MT 2106 2014 12 / 21
Numerical Analysis Numerical Dierentiation
Solution
x y y
2
y
3
y
4
y
0 7 6 24 48 0
2 13 30 72 48 0
4 43 102 120
6 145 222
8 367
John & Nasser (CoCIS) MT 2106 2014 13 / 21
Numerical Analysis Numerical Dierentiation
Solution 1
dy
dx
=
1
h
[y
0
+
(2p 1)
2

2
y
0
+
(3p
2
6p + 2)
6

3
y
0
]
But x = 1, x
0
= 0, h = 2, and
p =
(1 0)
2
=
1
2
dy
dx
=
1
2
[6 2] = 2
John & Nasser (CoCIS) MT 2106 2014 14 / 21
Numerical Analysis Numerical Dierentiation
Solution 2
Since x = 0 is one of the tabular points, using equation (4):
(
dy
dx
)
x=x
0
=
1
h
[y
0

1
2

2
y
0
+
1
3

3
y
0
]
Giving:
(
dy
dx
)
x=x
0
=
1
2
[6 12 + 16] = 5
John & Nasser (CoCIS) MT 2106 2014 15 / 21
Numerical Analysis Numerical Dierentiation
Second Order Derivatives
For the second order derivatives:
d
2
y
dx
2
=
d
dp
(
dy
dx
)
dp
dx
d
2
y
dx
2
=
d
dp
(
dy
dx
)
1
h
But
dy
dx
= [y
0
+
(2p 1)
2

2
y
0
+
(3p
2
6p + 2)
6

3
y
0
+
(4p
3
18p
2
+ 22p 6)
24

4
y
0
+ ....]
1
h
John & Nasser (CoCIS) MT 2106 2014 16 / 21
Numerical Analysis Numerical Dierentiation
Second Order Derivatives
Dierentiating eqn (3) wrt p gives:
d
dp
(
dy
dx
) =
1
h
[
2
y
0
+ (p 1)
3
y
0
+
(6p
2
18p + 11)
12

4
y
0
+ ....]
d
2
y
dx
2
=
1
h
2
[
2
y
0
+ (p 1)
3
y
0
+
(6p
2
18p + 11)
12

4
y
0
+ ....] (5)
Eqn (5) can be used to nd
d
2
y
dx
2
at a non-tabular value x
John & Nasser (CoCIS) MT 2106 2014 17 / 21
Numerical Analysis Numerical Dierentiation
Second Order Derivatives
For a tabular value, x = x
0
, substitute for p = 0 in eqn (5)
d
2
y
dx
2
=
1
h
2
[
2
y
0

3
y
0
+
11
12

4
y
0
+ ....] (6)
Equation (6) will be used to obtain
d
2
y
dx
2
at tabular points
John & Nasser (CoCIS) MT 2106 2014 18 / 21
Numerical Analysis Numerical Dierentiation
Example
Using the data table in the example above, nd
d
2
y
dx
2
at the points x = 1
and x = 0
Solution:
For the point x = 1, which is a non-tabular point, apply eqn (5)
d
2
y
dx
2
=
1
h
2
[
2
y
0
+ (p 1)
3
y
0
]
p =
(x x
0
)
h
=
1
2
(
d
2
y
dx
2
)
x=1
=
1
4
[24
1
2
(48)] = 0
John & Nasser (CoCIS) MT 2106 2014 19 / 21
Numerical Analysis Numerical Dierentiation
Example
For the point x = 0, which is a tabular point, apply eqn (6)
d
2
y
dx
2
=
1
h
2
[
2
y
0

3
y
0
]
(
d
2
y
dx
2
)
x=0
=
1
4
[24 48] = 6
John & Nasser (CoCIS) MT 2106 2014 20 / 21
Numerical Analysis Numerical Dierentiation
Verify
The polynomial that generated the data is:
y = x
3
3x
2
+ 5x + 7
Verify the values of
dy
dx
and
d
2
y
dx
2
at the points x = 0 and x = 1 obtained
using nite dierences
John & Nasser (CoCIS) MT 2106 2014 21 / 21

Você também pode gostar