Download presentation

Presentation is loading. Please wait.

Published byBarbara Stricklen Modified about 1 year ago

1
PROGRAM 8 consider a function y = f(x). In order to evaluate definite integral I = a ∫ b y dx = a ∫ b f(x) dx Divide the interval (b-a) of x into n equal parts starting from x 0 =a i.e. x o, (x 0 +h), (x 0 +2h),…..,(x 0 +nh). Width of each part =h = (b-a)/n The values of function y = f(x) at x o, (x 0 +h), (x 0 +2h),…..,(x 0 +nh) are y 0,y 1,y 2,……y n respectively. Then using Newton’s formula I = a ∫ b f(x) dx = x 0 ∫ xo+nh f(x) dx Then using Newton’s formula,s I = h[ny 0 + (n 2 /2) ∆y 0 + { (n 3 /3 ) – (n 2 /2)}(∆ 2 y o /2!) + ………] ……..(1) Equation (1) is known as general quadrature formula. TRAPEZOIDAL RULE : Taking n = 1 and neglecting second and higher order terms x0 ∫x0+h y dx = h [ ( y 0 + ∆y 0 /2) ] = h [ y 0 + (y 1 -y 0 )/2 ] = (h/2) [ y 0 + y 1 ] Similarly for the next intervals, x0+h ∫ x0+2h y dx = (h/2) [ y 1 + y 2 ].. x0+(n-1) h ∫ x0+nh y dx = (h/2) [ y n-1 + y n ]

2
On adding all these terms,(i.e. by Trapezoidal Rule the value of definite or finite integral is given by I = a ∫ b y dx = (h/2) [ ( y 0 +y n ) + 2( y 1 + y 2 +….+y n-1 )] I = (h/2) [ (sum of first and last terms ) + 2 (sum of remaining terms )] where y 0 = F( x o ) = F (a) y 1 = F( x o + H ) = F (a + H) y 2 = F( x o + 2H ) = F (a +2 H). y n = F( x o + nH ) = F (a +n H) =F (b)

3
C PROGRAM : USE TRAPEZOIDAL RULE FOR EVALUATING DEFINITE INTEGRAL OF FUNCTION F=1-EXP(-X/2.0) C MAIN PROGRAM WRITE(*,*)’GIVE INITIAL AND FINAL VALUES OF X’ READ(*,*) A, B WRITE(*,*)’GIVE THE SEGMENT WIDTH’ READ(*,*) H 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(*,*)’INTEGRAL BETWEEN’,A,’AND’,B WRITE(*,*)’WHEN H =‘, H, ‘IS’, RESULT STOP END C ……END OF MAIN PROGRAM…….

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

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google