Вы находитесь на странице: 1из 10

1.

Numerical Differentiation

Need for differentiation of a function aries quite often in engineering and scientific
problems. In many situations, we may not know the exact function.What we know is only
the values of the function at a discrete set of points.We are given the distance travelled by
a moving object at some regular time intervals and asked to determine its velocity at a
particular time. In some other instances, the function is known but it is so complicated that
an analytic differentiation is difficult.We seek the help of numerical techniques to obtain
the estimates of function derivatives. The method of obtaining the derivative of a function
of function using a numerical technique is known as numerical differentiation.

Numerical differentiation deals with the following problem: We are given the function
= y f(x) and wish to obtain one of its derivatives at the point x= x
i
. The term given
means that we either have an algorithm for computing the function or possess a set of
discrete data points ) , (
i i
y x , , 0 = i 1,,n. In either case, we have access to a finete number
of ) , ( y x data pairs from which to compute the derivative.


Figure 1




We discuss the numerical process of approximating the derivative ) (x f ' of a function
f(x) when the function itself is available.

1.1 First order derivatives

1.1.1 Two-Point Forward Difference Formula
The derivative of the finite difference approximations for the derivatives of f(x) is based on
forward Taylor series expansion of f(x) about x
i
, such as
( ) ( )
x
x f x x f
x
y
i i
A
A +
=
A
A
+ ' ' ' + ' ' + ' + = + ) (
! 3
) (
! 2
) ( ) ( ) (
3 2
i i i i i
x f
h
x f
h
x f h x f h x f


Figure 2: 2- Point Forward Difference

In the representation of the discrete function, h is just the sampling interval. If we neglect
those terms that contain the 2nd and higher order derivatives, then we get
h
x f x f
x x
x f x f
x f
i i
i i
i i
i
) ( ) ( ) ( ) (
) (
1
1
1

=

~ '
+
+
+
,
h x x x x
i i i i
= =
+ 1 1

though we see that there is an error whose largest component is proportional to h.This formula
is called the first order difference formula and the error is of order O(h). This is also known
as two-point forward difference .
As the h gets smaller the error will get smaller .

( )
( ) ( )
Error
i 1 i
i

|
.
|

\
|

= '
+
h
x f x f
x f


( ) ( )
! 3 ! 2
Error
i
2
i
+ ' ' ' + ' ' = x f
h
x f
h

Example 1.1.1
Estimate approximate derivative of
2
) ( x x f = at 1 = x , for , 2 . 0 = h 0.1 , 0.05 and 0.01
using the first order forward difference formula.
Solution 1.1.1
) (x f '
h
x f x f
i i
) ( ) (
1

=
+

h
f h f
f
) 1 ( ) 1 (
) 1 (
+
= '

Derivative approximations are tabulated below:
h f (1) Error
0.2 2.2 0.2
0.1 2.1 0.1
0.05 2.05 0.05
0.01 2.01 0.01

Note that the correct answer is 2. The derivative approximation approaches the exact value as
h decreases. The error decreases proportionally with decrease in h.

1.1.2 Two Point Backward Difference Formula
The derivative of the finite difference approximations for the derivatives of f(x) is based on
backward Taylor series expansion of f(x) about x
i
, such as
+ ' ' ' ' ' ' = ) (
! 3
) (
! 2
) ( ) ( ) (
3 2
i i i i i
x f
h
x f
h
x f h x f h x f


Figure 3: 2- Point Backward Difference
If we neglect those terms that contain the 2nd and higher order derivatives, then we get

1
1
) ( ) (
) (

~ '
i i
i i
x x
x f x f
x f
,
h x x x x
i i i i
= =
+ 1 1

This formula is called the first order backward difference .This is also known as two-point
backward difference .
Example 1.1.2
Use backward difference approximations to estimate the first derivative of

2 . 1 25 . 0 5 . 0 15 . 0 1 . 0 ) (
2 3 4
+ = x x x x x f

at x = 0.5 with h = 0.5 and 0.25 (exact sol. = -0.9125)
Solution 1.1.2
1
1
) ( ) (
) (

~ '
i i
i i
x x
x f x f
x f

1
=
i i
x x h

% 7 . 21 , 714 . 0
25 . 0
10351563 . 1 925 . 0
25 . 0 5 . 0
) 25 . 0 ( ) 5 . 0 (
) 5 . 0 ( , 25 . 0
% 7 . 39 , 55 . 0
5 . 0
2 . 1 925 . 0
0 5 . 0
) 0 ( ) 5 . 0 (
) 5 . 0 ( , 5 . 0
t
t
= =

= ' =
= =

= ' =
c
c
f f
f h
f f
f h

1.1.3 Two Point Central Difference
The other approach to decreasing discretisation error is to obtain a higher order
approximation from the Taylor Series. By using another point from the discrete function we
can eliminate the largest term in the error. Substituting -h for h in the expression for the
Taylor Series gives:
+ ' ' ' + ' ' + ' + = + ) (
! 3
) (
! 2
) ( ) ( ) (
3 2
i i i i i
x f
h
x f
h
x f h x f h x f

+ ' ' ' ' ' ' = ) (
! 3
) (
! 2
) ( ) ( ) (
3 2
i i i i i
x f
h
x f
h
x f h x f h x f


Figure 4: 2- Point Central Difference

h x f x f x f
h x f x f x f
h x f x f x f
i i i
i i i
i i i
) ( 2 ) ( ) (
_____ __________ __________
) ( ) ( ) (
) ( ) ( ) (
1 1
1
1
' =
' =

' + =
+

+

Thus we have
h
x f x f
x f
i i
i
2
) ( ) (
) (
1 1 +

= '

This formula is called the centered divided difference formula and the error is of order O(h
2
).
Example 1.1.3
Use forward and backward difference approximations to estimate the first derivative of

2 . 1 25 . 0 5 . 0 15 . 0 1 . 0 ) (
2 3 4
+ = x x x x x f

at x = 0.5 with h = 0.5 and 0.25 (exact sol. = -0.9125)
Solution 1.1.3
h
x f x f
x f
i i
i
2
) ( ) (
) (
1 1 +

= '

% 4 . 2 , 934 . 0
5 . 0
10351563 . 1 63632813 . 0

25 . 0 75 . 0
) 25 . 0 ( ) 75 . 0 (
) 5 . 0 ( , 25 . 0
% 6 . 9 , 0 . 1
1
2 . 1 2 . 0
0 1
) 0 ( ) 1 (
) 5 . 0 ( , 5 . 0
t
t
= =

= ' =
= =

= ' =
c
c
f f
f h
f f
f h

1.2 Higher Order 1st Derivative

1.2.1 Three Point Forward Difference
The formula below estimate the value of the derivatives at the endpoints making use of all
three points most often giving a more accurate value for the derivative. High-accuracy
divided-difference formulas can be generated by including additional terms from the Taylor
series expansion.

2
) ( ) ( ) (
) (

2
) (
) ( ) ( ) (
1
2
1

' '

= '
+
' '
+ ' + =
+
+
h
x f
h
x f x f
x f
h
x f
h x f x f x f
i i i
i
i
i i i


Figure 5:Three Point Forward Difference

) (
) ( ) ( 2 ) ( ) ( ' ) ( '
) (
2
1 2 1
h O
h
x f x f x f
h
x f x f
x f
i i i i i
i
+
+
=

= ' '
+ + +

) (
2
) ( ) ( 2 ) ( ) ( ) (
) (
2
2
1 2 1
h O h
h
x f x f x f
h
x f x f
x f
i i i i i
i
+
+

= '
+ + +

Inclusion of the 2
nd
derivative term has improved the accuracy to O(h
2
).
Thus, we have
) (
2
) ( 3 ) ( 4 ) (
) (
2 1 2
h O
h
x f x f x f
x f
i i i
i
+
+
= '
+ +

This is a three-point forward difference formula.
Example 1.2.1
Use forward difference approximations of
2
(h O ) to estimate the first derivative
of
2 . 1 25 . 0 5 . 0 15 . 0 1 . 0 ) (
2 3 4
+ = x x x x x f

at x = 0.5 with h = 0.25 (exact sol. = -0.9125)
Solution 1.2.1
) (
2
) ( 3 ) ( 4 ) (
) (
2 1 2
h O
h
x f x f x f
x f
i i i
i
+
+
= '
+ +

% 82 . 5 , 859375 . 0
5 . 0
) 925 . 0 ( 3 ) 6363281 . 0 ( 4 2 . 0
) 25 . 0 ( 2
) 5 . 0 ( 3 ) 75 . 0 ( 4 ) 1 (
) 5 . 0 (
t
= =
+
=
+
= '
c
f f f
f

1.2.2 Three Point Backward Difference
High-accuracy divided-difference formulas can be generated by including additional terms
from the Taylor series expansion.

' '
' =

2
1
2
) (
) ( ) ( ) ( h
x f
h x f x f x f
i
i i i
1
1
) ( ) (
) (

~
'
i i
i i
x x
x f x f
x f


Figure 6: Three Point Forward Difference
We can obtain a three-point backward difference Formula by replacing h by h in this
equation
h
x f x f x f
x f
i i i
i
2
) ( 3 ) ( 4 ) (
) (
1 2
+
= '
+ +

The three-point backward difference Formula is given by
h
x f x f x f
x f
i i i
2
) ( ) ( 4 ) ( 3
) (
2 1
+
~ '

Example 1.2.2
Use backward difference approximations of
2
(h O ) to estimate the first derivative
of
2 . 1 25 . 0 5 . 0 15 . 0 1 . 0 ) (
2 3 4
+ = x x x x x f

at x = 0.5 with h = 0.25 (exact sol. = -0.9125)
Solution 1.2.2
h
x f x f x f
x f
i i i
2
) ( ) ( 4 ) ( 3
) (
2 1
+
~ '

% 77 . 3 , 878125 . 0
5 . 0
2 . 1 ) 035156 . 1 ( 4 ) 925 . 0 ( 3
) 25 . 0 ( 2
) 0 ( ) 25 . 0 ( 4 ) 5 . 0 ( 3
) 5 . 0 (
t
= =
+
=
+
= '
c
f f f
f


2. GRAPHICAL USER INTERFACE (GUI)
2.1. Introduction to GUI
Two-point forward difference


Two-point backward difference


MATLAB version R2009b is used in this project. Both earlier versions and new versions should
be compatible as well.

3. MATLAB WEB SERVER

3.1 What Is Matlab Web Server?
The MATLAB Web Server is a special toolbox to access MATLAB Simulations from the
web. We installed this server in the environment of a HyperWave Information Server and got
good results using this tool for teaching electrical engineering and mathematical modeling.
The matlab web server enables us to create matlab applications that use the capabilities of the
World Wide Web to send data to matlab for computation and to display the results in a web
browser. MATLAB programs, the Matlab Web Server toolbox and the web server run on the
remote server station.

Figure 3.1: Matlab Web Server
The web information is stored in the Web pages.The web pages are stored in the computers
called Web servers.The computer reading the pages is called web clients with specific web
browser.The web server waits for the request from the web clients over the Internet.



Figure 3.2:The HTTP Request/Response Model

2.1 Building MATLAB Web Server Applications
MATLAB Web Server applications are a combination of M-files, Hypertext Markup
Language (HTML), and graphics. Knowledge of MATLAB programming and basic HTML
are the only requirements [ 1].
The application development process requires a small number of simple steps:

Вам также может понравиться