Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

University of Palestine

Gaza Strip

Civil Engineering College


Numerical analysis
CIVL 3309
Formerly CVL 3308

Dr. Suhail Lubbad


Numerical Differentiation
What does a derivative really mean?

It is the rate of change of a function (dependent variable) at a SPECIFIC


value of the independent variable

Example from real life

Spend VS Income

Spend is the dependent variable, the Function.


Income is the independent variable.
d Spend
Spend ' =
d Income

d *dependent variable+
Spend '= means derivative, and so is d
d *independent variable+

The rate by which the spend changes according to the income

Spend Vs Time

Spend is the dependent variable, the Function.


Income is the independent variable.

d Spend
Spend ' =
d Time

The rate by which the spend changes according to time


Positive derivative means the rate of change is increasing

Negative derivative means the rate of change is decreasing

Zero derivative means ZERO rate of change


Optimum: maximum of minimum of the dependent
variable at that specific value if the independent
Variable,
REMEMBER THE SPEND AT START AND END OF THE MONTH
Consider a linear function (a line through two points)

f(x)=Y represented by a straight line

Considering any two points [* x1 y1 + , * x2, y 2+]


Newton quotient, or the difference quotient

,F F *x 2 +−F *x1 + y 2−y 1


Slope of that line = = = =CONSTANT
,x x 2−x 1 x 2 −x1

What does this slope mean? rate of change


In life and Science, linearity is just a special case

What about non-linear functions 'Curves'


A car on the road changes direction at a one single point

by twisting the wheels around

Rate of change of the direction depends on how big the twist of the
wheels is

Not on

any other point further away in the road

THE SAME APPLIES FOR THE SPEED


To Calculate the rate of change using another point on the road
as done for lines, will depend on how far that point on the road (curve) is.

Yet Still
Different points give different values !!!
Those different values are averages

We need the line through only that point on the curve


at which we compute the Rate of change.

That line is known as the tangent line.


A tangent is a straight line that just touches the curve

How to compute the exact rate of change at a point?

You can't apply the relation , y why?


,x
Find that tangent
HOW
Use the secant of the Curve

A secant is a straight line that cuts a curve

average rate of change between those two points is the slope of the secant.

,y F *Q+−F *P+
Slope of the secant = =
,x ,x
BUT
What is the rate of change exactly at at the point x?
Or what is the slope of the tangent at the point x?

Take shorter and shorter intervals (distances between the x's)


The slope of the tangent line at P, is the limit of the change in the
function divided by the change in the independent variable as that change
in the independent variable approaches 0.

,y F *Q+−F * P+
Slope of the tangent = F ' = lim = lim
, x )0 ,x , x )0 ,x

Δx: is the variable that approaches 0,


x remains constant,
Thus that limit will be a function of x
To simplify the expression

Rewrite
,x)h
the newton quotent becomes :
F *x'h+−F *x+
h

The derivative of the Function F(x)


F * x'h+−F * x +
lim
h)0 h
Example

2
F *x+=x
2 2
F *x'h+=x 'h '2xh
then
2
F *x'h+−F *x+ 2hx'h
= =2x
h h
derive it the way you learned in CALCULUS
Graphical Differentiation
One should be able to estimate the shape of the derivative of a plotted
function; it is not required for exams in our course, but it makes it sure
you understand the idea of derivatives .
Algebraic differentiation background

n
y=x y '=nx n−1

n du
y= * u *x++ y '=nu n−1

dx

du dv
y=uv y '=v 'u
dx dx

du dv
v −u
u dx dx
y= y '= 2
v v
Numerical Differentiation

The basic derivation of the formulae are obtained from the Taylor
expansion, as was done before: the same slides are here once again
Finite difference technique :

1- Taylor expansion theorem


A one variable functions that have n continuous derivatives over
the interval [x1 , x2], are approximated as follows:

2
h h n−1
f n−1 * x+ ∣x 'O * h +
n
f * x0 'h+=f *x 0 +'h f '*x +∣x ' f ' ' * x +∣x '⋯'
0
2! 0
* n−1 + ! 0

Where x 1 (x 0 (x 0'h(x 2 .
Simple Finite Difference Approximation to a Derivative

Truncate the taylor expansion form to the first derivative


term with ERROR of order h2.

Forward finite divided difference Backward finite divided difference


f * x0 'h +=f * x0 +'h f '*x +∣x ' O * h + f * x0 −h +=f * x0 +−h f '* x+ ∣x 'O * h +
n n
0 0

Rearranging Rearranging
f * x0 'h+−f * x0 + f * x0 +−f * x0 −h+
'O * h + =f '*x 0 + ' O * h + =f '* x 0 +
n n

h h
O * hn + ) 0 O * hn + ) 0

f * x0 'h+−f * x0 + f * x0 +−f * x0 −h+


=f '* x0 + =f '* x0 +
h h
Forward Difference Formulae with O(h) error

f *xi '1 +−f *x i +


f '*x i +=
h

f *xi '2 +−f *x i '1+ f *xi '1 +−f *x i +


f '*x i'1 +−f '*xi + −
h h
f ''*x i + = = =
h h

f *x i'2 +−2 f *x i'1+'f *x i +


2
h

Similarly
f *x i'3 +−3f *x i'2 +'3f *x i '1 +−f *x i +
f '' '*x i += 3
h
Backward Difference Formulae with O(h) error

f *x i +−f *x i−1 +
f '* xi +=
h

f *x i +−f *x i−1 + f * x i−1 +−f *x i−2 +



f '* x i +−f ' *x i−1 + h h
f ' '*x i + = = =
h h

f * x i +−2 f * x i−1 +'f *x i−2 +


2
h

Similarly
f *x i +−3f *x i−1 +'3f *x i−2 +−f * x i−3 +
f ' ''*x i += 3
h
Centered Difference Formulae with O(h 2) error

f *x i'1 +−f *x i−1 +


f '* xi += backward forward
2 h

f *x i'1 +−f * x i + f * xi +−f *x i−1 +



1 1
h h
f '* x i'1 +−f '* x i−1 + 2 2
f ' '*x i + = = =
2 h 2 h

f * x i'1 +−2 f *x i +'f *x i−1 +


2
h

Similarly
f *x i'2 +−2 f *x i'1 +'2 f *x i−1 +−f *x i−2 +
f ' ''*x i += 3
2 h
Can we compute the true ERROR?

Yes, find out how.


Exercise 1
Suppose you are given the data in the following table.

T 0.0 0.5 1.0 1.5 2.0

Y 0.0 0.19 0.26 0.29 0.31

Give the forward, backward and central difference approximations of f′ (1).


Give the central difference approximations for f′′ (1) and f′′′ (1)
Exercise 2
Let: f(x)=cos(x)

Use the Centered Formula with h=0.1, 0.01, 0.001


to find the approximation to f ′′ (0.8) .

Compare with the true value f ′′ (0.8) = − cos(0.8),


in the sense of finding the Error !
Carry nine decimal places in all calculations.

Lets first take f'(0.8) with h= 0.1

ff '(0.8) = [ f(0.9) – f(0.8)]/ 0.1 = [ cos(0.9) – cos(0.8)]/ 0.1


= ?? find it out

Do the same for fb' and fc'


Check the true error for each trial

Then find out the f''(0.8) and compare it with the true f'' = – cos(0.8)
Example 23.1

Recompute f ', f '' with error of order h, and f '''

4 3 2 x
f *x+=− 0.1x − 0.15x − 0.5x − 0.25 '1.2

You might also like