You are on page 1of 2

COMPUTER APPLICATION IN PETROLEUM INDUSTRY (PE 315)

EXERCISE # 3
MATLAB
DIFFERENTIATION AND INTEGRATION
1. Assume a function is defined on grid,

Where is

x the sampling interval and N is the total number of samples, or grid-points. The

simplest possible numerical derivative of a function

f (x)

can be de computed using the one-

f (x)

for all grid points, k= 0, 1, ---N-1.

sided approximation

Write MATLAB script to compute the derivative of


Test the on the function

Where 0 x 2 , N =100 and x

Where 0 x 10 . Assume

x0

2
( N 1 ) . Also check the script on the function

= 5.0, N =100 and x

10
= ( N 1 ) .

Compute both the numerical derivative and the difference between the numerical derivative and
the exact derivative. Make plots of the error.
2. If we want to evaluate the integral,
x

I ( x )= f ( x ' ) d x '
a

Numerically, the simplest approach is to replace the integral with a sum


N1

I ( x )= f ( k x ) x
k=0

Where

'

x =k x

and x=( N1 ) x .

Make MATLAB script to perform integration of

f ( x )=exp (x )

0 x 1 . Use also the trapezoidal rule and compare the results.

on the interval

You might also like