-florian66-

cos

Aug 27th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program test
  2. implicit none
  3.  
  4. real :: angle, ret
  5.  
  6.     PRINT *, 'Enter an angle (in radian)'
  7.     read *, angle
  8.     print *,'real_cos(', angle, ') =', cos(angle) ! real cosinus
  9.     call cos2(angle, 12, ret)
  10.     print *,'cos(', angle, ') = ', ret ! cosinus calculate
  11.  
  12. end  program test
  13.  
  14. subroutine cos2(angle, n, ret)
  15.     implicit none
  16.  
  17.     integer :: i, n, a, b
  18.     real :: angle, ret
  19.  
  20.     a = 8*n - 6
  21.     b = 2*n * (2*n - 1)
  22.  
  23.     ret = 1.000000
  24.  
  25.     do i = 1, n
  26.  
  27.         ret = 1 - (angle * angle * ret) / b
  28.         b = b - a
  29.         a = a - 8
  30.  
  31.     end do
  32.  
  33.     !return ret
  34.  
  35. end subroutine cos2
Advertisement
Add Comment
Please, Sign In to add comment