- #1

dss91

- 5

- 0

## Homework Statement

I have an assignment to write a program for calculating the sine (and various other functions) using the method of truncated infinite series using DO statements. The DO statement is supposed to run until the difference between the current and last iterations are less than 1.0E-6. Saying that I am lost is an understatement. I have done some research on the internet and seem to have been able to piece together some code which makes sense to me, however I am just getting random junk out of it when I run it. Any help would be greatly appreciated! There are multiple menu options for different functions, which I have yet to start on, as I am trying to get the sine function to work correctly first.

I put a "!" in front of the IF statement on the accuracy checker to see if it would even compute the sine to 10000 terms correctly, but that doesn't even seem to work!

## The Attempt at a Solution

Code:

```
PROGRAM PROJECT2
IMPLICIT NONE
INTEGER::i,n
REAL::x,z,sinx,cosx
CHARACTER::choice
WRITE(*,*) 'Please enter a number x:'
READ(*,*) x
DO
WRITE(*,*) ''
WRITE(*,*) ' Iterative Function Calculator'
WRITE(*,*) '-------------------'
WRITE(*,*) ' A) SIN(x)'
WRITE(*,*) ' B) COS(x)'
WRITE(*,*) ' C) e^x'
WRITE(*,*) " D) Lambert's W function Wo(x)"
WRITE(*,*) ' E) Enter a new x'
WRITE(*,*) ' Q) Quit'
WRITE(*,*) 'Please enter choice:'
READ(*,*) choice
IF(CHOICE .EQ. 'Q' .or. CHOICE .EQ. 'q') THEN
EXIT
ELSE IF(CHOICE .EQ. 'A' .or. CHOICE .EQ. 'a') THEN
DO i = 1,n
n=1
sinx=0.
sinx=sinx+z
n=n+1
z=z+(-1)**n*x**(2*n+1)/((2*n-2)*(2*n-1))
IF(n==10000) THEN
EXIT
!IF((abs(sinx-(sinx+z))) < (1.E-6)) THEN
!EXIT
END IF
END DO
WRITE(*,*) z
!WRITE(*,'(A,F6.4,A,F6.4 )') 'SIN(',x,') = ',sinx
ELSE IF(CHOICE .EQ. 'D' .or. CHOICE .EQ. 'd') THEN
READ(*,*) x
ENDIF
END DO
END PROGRAM
```