PROGRAM series15 ! ! Author: Br. David Carlson ! ! Date: December 31, 1999 ! ! Last Revised: May 2, 2004 ! ! This program uses Taylor series to find an approximate value for the ! integral of sin(x) from 0 to pi. Compare with the output of integ3.f90. ! Of course, a series approximation is unnecessary, as is any numerical ! approximation, since the exact answer is known from calculus as 2. IMPLICIT NONE REAL::x, xsquared, term, sum WRITE (*, 20) 20 FORMAT (1X, 'Program to integrate sin(x) from 0 to pi using series') x = 2.0 * ASIN(1.0) ! Calculate the value of pi. sum = 0.0 xsquared = x * x term = xsquared sum = sum + term / 2.0 term = term * xsquared sum = sum - term / 24.0 term = term * xsquared sum = sum + term / 720.0 term = term * xsquared sum = sum - term / 40320.0 WRITE (*, 200) sum 200 FORMAT (1X, 'The approximate value is ', E16.8) END PROGRAM