0% found this document useful (0 votes)
10 views

N 1) - Also Check The Script On The Function

This document provides instructions for two MATLAB exercises involving differentiation and integration. The first exercise involves writing a script to numerically compute the derivative of two test functions using a one-sided approximation. The script should also compute the error between the numerical and exact derivatives. The second exercise involves writing a script to numerically integrate the function f(x)=exp(-x) from 0 to 1 using the simplest approach of replacing the integral with a sum, and also using trapezoidal rule for comparison.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

N 1) - Also Check The Script On The Function

This document provides instructions for two MATLAB exercises involving differentiation and integration. The first exercise involves writing a script to numerically compute the derivative of two test functions using a one-sided approximation. The script should also compute the error between the numerical and exact derivatives. The second exercise involves writing a script to numerically integrate the function f(x)=exp(-x) from 0 to 1 using the simplest approach of replacing the integral with a sum, and also using trapezoidal rule for comparison.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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