Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Truncated Infinite Series

Status
Not open for further replies.

frtran90

Programmer
Feb 19, 2009
11
US
trying to write a program that will do a truncated infinite series to calculate the sin of x. I need the do loop to end when the term is within the user input for accuracy.

anybody know how i can finish it?

i've got this so far.
Program sinx
Implicit none

!declare variables

real::x, sum, term, accuracy
real::deg2rad=(3.14159/180)
integer::term_number, i
write(*,*)'enter number x in degrees to find sin of x'
read(*,*)x
write(*,*)'Enter required accuracy'
read(*,*)accuracy


!convert x to radians
x=x*deg2rad
write(*,*)'x in radians is ',x

!calculate sum

term_number=1
term = x
sum = 0.0

do i=1, term_number
sum=sum+term
term_number = term_number+1
term = term * (-1) * (x**2)/((2*term_number-2)*(2*term_number-1))
if((abs(sum-(sum+term+1)))<(accuracy))
exit

!evaluate the term and exit the loop if necessary

end do
!display results: sinx and the number of terms required
end program
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top