We are hiring content writers to work from home

Resources » Articles/Knowledge Sharing » Computer & Technology

# understanding Trapezoidal Rule using Fortran

 Posted Date: 12-Mar-2008 Last Updated: 12-Mar-2008 Category: Computer & Technology Author: ashish singh Member Level: Gold Points: 4

Numarical Integration using Trapezodial Rule

The general problem of Numerical Integration may be stated as follows. Given a set of data points (x0,y0),(x1,y1),(x2,y2)……….(xn,yn) of a function y=f(x), where f(x) is not known explicitly, it is required to compute the value of the definite integral.
Trapezoidal Rule is one of the most important and simple way to solve Numerical Integration problem.
Let h be the interval between two successive value of x and for each value of f(x) and this process is started from initial value of x, x is increases in every step by h. Therefore finally we get a table of (x0,y0),(x1,y1),(x2,y2)……..(xn,yn) where y0=f(x0),y1=f(x1)………..yn=f(xn) and x1=x0+h,x2=x1+h…………xn=xn-1+h.
At last by using following formula –
I=(h*(y0+2(y1+y2+………yn-1)+yn))/2
Required condition for this formula or Trepezoidal Rule n must be atleast 2 where n is no. of strips.

Fortran Program for Trapezoidal rule :

C PROGRAM FOR INTEGRATION BY USING TRAPEZOIDAL RULE

FUNCTION F(X)
F=1-EXP(-X/2.0)
RETURN
END

WRITE(*,*)'Give initial value X'
WRITE(*,*)'Give final value X'

WRITE(*,*)'What is the Segmnet width?'
N=(B-A)/H

SUM=(F(A)+F(B))/2.0
DO 10 I=1,N-1
SUM=SUM+F(A+I*H)
10 CONTINUE

RESULT=SUM*H

WRITE(*,*)
WRITE(*,*) 'INTEGRATION BETWEEN',A,'AND',B
WRITE(*,*)
WRITE(*,*) 'WHEN H=',H,'IS',RESULT
WRITE(*,*)
STOP
END
Output

TRAPEZOIDAL RULE

D:\FORTRAN\BINB>TRAP2
Give initial value X
0.0
Give final value X
10.0
What is the Segmnet width?
.5

INTEGRATION BETWEEN 0.000000E+00AND 10.000000

WHEN H= 5.000000E-01 IS 8.003140

Stop - Program terminated.

D:\FORTRAN\BINB>TRAP2
Give initial value X
2
Give final value X
5
What is the Segmnet width?
.2

INTEGRATION BETWEEN 2.000000AND 5.000000

WHEN H= 2.000000E-01IS 2.246078

Stop - Program terminated.

Did you like this resource? Share it with your friends and show your love!

Responses to "understanding Trapezoidal Rule using Fortran"

No responses found. Be the first to respond...

Feedbacks

## Post Comment:

• Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
• No HTML formatting and links to other web sites are allowed.
• This is a strictly moderated site. Absolutely no spam allowed.
•  Name: Sign In to fill automatically. Email: (Will not be published, but required to validate comment) Type the numbers and letters shown on the left.

 Next Resource: understanding Lagranges Interpolation in Numerical Analysis Previous Resource: understanding simpsons 1/3rd rule using Fortran for integration Return to Resources Post New Resource Category: Computer & Technology

Post resources and earn money!

More Resources
 Popular Tags Tag posting guidelines Search Tags

### Subscribe to Email

• Get Jobs by Email
• Forum posts by Email
• Articles by Email