handout3_solutions

# handout3_solutions - solutions.txt Mon Oct 10 15:51:18 2011...

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: solutions.txt Mon Oct 10 15:51:18 2011 1 1: 2:******************************************* 3:./exercise4/mclau.f90 4: 5:PROGRAM mclau 6:!** Program to calculate SIN(x) to ‘n’ terms of the Mclaurin Series 7:!** NOTE 8:!** Limit is at 10**38 for REAL type that is 9:!** 10:!** factorial 34 = 2.9523282E+38 11:!** factorial 35 = Infinity occurs at term 18 12:!** NOTE compiler clever and reworks math in loop to avoid REAL limitation here 13:!** HOWEVER Not as clever as our mclau2.f90 code 14: 15: IMPLICIT NONE 16: 17: INTEGER :: i,sign=-1,n 18: REAL :: sinx,x,fact=1 19: 20: PRINT*,’Enter the value of x you require: ’ 21: READ*,x 22: PRINT*,’Enter the number of terms you require: ’ 23: READ*,n 24: 25: sinx=x 26: PRINT*,’Calculating Term’,1 27: 28: DO i=3,2*n-1,2 29: !** Loop through starting with the second term (-x^3/3!) ans stopping 30: !** loops up to 2*n-1 for the last term. 31: 32: PRINT*,’Calculating Term’,(i-1)/2+1 33: fact=fact*i*(i-1) ! *** Calculate to rquired factorial 34: sinx=sinx+sign*x**i/fact ! *** Calculate the new approximation 35: sign=-sign ! *** update the sign parameter 36: END DO 37: 38: PRINT*,’The approximation is for x=’,x 39: PRINT*,’Number of terms in the approximation = ’,n 40: PRINT*,’The approximation =’,sinx 41: PRINT*,’The true value is =’,SIN(x)...
View Full Document

## This note was uploaded on 02/13/2012 for the course MATH 5806 taught by Professor Brooks during the Fall '10 term at Minnesota.

### Page1 / 2

handout3_solutions - solutions.txt Mon Oct 10 15:51:18 2011...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online