1 / 4

C PROGRAM : USE TRAPEZOIDAL RULE FOR EVALUATING

magee
Download Presentation

C PROGRAM : USE TRAPEZOIDAL RULE FOR EVALUATING

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  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) [ ( y0+yn) + 2( y1 + y2 +….+yn-1 )] I = (h/2) [ (sum of first and last terms ) + 2 (sum of remaining terms )] where y0 =F(xo) = F (a) y1 =F(xo + H) = F (a + H) y2=F(xo + 2H) = F (a +2 H) . . yn =F(xo + 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

More Related