View previous topic :: View next topic |
Author |
Message |
Jim
Joined: 21 Jul 2006 Posts: 24 Location: USA
|
Posted: Mon Oct 31, 2011 1:17 pm Post subject: Trigonometric Functions COS and SIN. |
|
|
My program is calculating incorrect numbers for the following code:
DLS1(K)=COS(INC(K-1))
DLS2(K)=COS(INC(K))
DLS3(K)=SIN(INC(K-1))
DLS4(K)=SIN(INC(K))
DLS5(K)=COS(AZM(K)-AZM(K-1))
DLS(K)=ACOS(DLS1(K)*DLS2(K)+DLS3(K)*DLS4(K)*DLS5(K))*(100/CL(K))
K is an array of angles. Any help with trig functions?
I took the COS of several angles on my calculator and they are not the same as what the program calculates.
Jim |
|
Back to top |
|
 |
brucebowler Guest
|
Posted: Mon Oct 31, 2011 1:53 pm Post subject: |
|
|
Are INC specified in degrees or radians? |
|
Back to top |
|
 |
Jim
Joined: 21 Jul 2006 Posts: 24 Location: USA
|
Posted: Mon Oct 31, 2011 2:35 pm Post subject: Trig functions. |
|
|
Specified in degrees. |
|
Back to top |
|
 |
JohnHorspool
Joined: 26 Sep 2005 Posts: 270 Location: Gloucestershire UK
|
Posted: Mon Oct 31, 2011 3:56 pm Post subject: |
|
|
Trig functions in fortran use radians not degrees. _________________ John Horspool
Roshaz Software Ltd.
Gloucestershire |
|
Back to top |
|
 |
Wilfried Linder
Joined: 14 Nov 2007 Posts: 314 Location: D�sseldorf, Germany
|
Posted: Mon Oct 31, 2011 4:09 pm Post subject: |
|
|
As John mentioned, you need radians. Use
alfa_new = alfa_old*datan(1.D0)/x with
x = 45.D0 for input values in degrees
x = 50.D0 for ... grads
x = 800.D0 for ... mils
Regards - Wilfried |
|
Back to top |
|
 |
mecej4
Joined: 31 Oct 2006 Posts: 1899
|
Posted: Mon Oct 31, 2011 6:41 pm Post subject: |
|
|
In addition to the other points that have been noted, make sure that the arguments to the trigonometric functions are REAL or DOUBLE PRECISION, not INTEGER (which INC would be, by default). |
|
Back to top |
|
 |
ebarbero
Joined: 01 Aug 2012 Posts: 20
|
Posted: Sat Aug 18, 2012 9:37 pm Post subject: cosd, sind |
|
|
I have used COSD(Arg) and SIND(Arg) with Arg in Degrees with Intel compilers, but I guess these are extensions not supported by FTN95. They must be non-standard extensions. _________________ http://www.cadec-online.com/ |
|
Back to top |
|
 |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2402 Location: Yateley, Hants, UK
|
Posted: Sun Aug 19, 2012 10:25 am Post subject: |
|
|
... but they must be among the easiest routines to write yourself!
(Well, they were in Fortran 77. Now, you have to make them generic, I suppose)
Eddie |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Mon Aug 20, 2012 4:51 am Post subject: |
|
|
Here is a possible way to have it generic using a module, although I wonder how useful it is ? Code: | module degrees
!
real*10, parameter :: deg_to_rad = 0.0174532925199432957692_3 ! radians per degree
!
interface sin_d
module procedure sin_d4, sin_d8, sin_d10
end interface sin_d
interface cos_d
module procedure cos_d4, cos_d8, cos_d10
end interface cos_d
!
contains
!
real*4 function sin_d4 (x)
real*4 :: x
sin_d4 = sin (x*deg_to_rad)
end function sin_d4
!
real*8 function sin_d8 (x)
real*8 :: x
sin_d8 = sin (x*deg_to_rad)
end function sin_d8
!
real*10 function sin_d10 (x)
real*10 :: x
sin_d10 = sin (x*deg_to_rad)
end function sin_d10
!
real*4 function cos_d4 (x)
real*4 :: x
cos_d4 = cos (x*deg_to_rad)
end function cos_d4
!
real*8 function cos_d8 (x)
real*8 :: x
cos_d8 = cos (x*deg_to_rad)
end function cos_d8
!
real*10 function cos_d10 (x)
real*10 :: x
cos_d10 = cos (x*deg_to_rad)
end function cos_d10
!
end module degrees
PROGRAM deg
!
use degrees
!
INTEGER i
real*4 x4
real*8 x8
real*10 x10
!
real*10 one, forty_five
one = 1
forty_five = 45
write (*,*) deg_to_rad, atan (one) / forty_five, deg_to_rad - atan (one) / forty_five
!
DO i=0,90,5
x4 = i
x8 = i
x10 = i
write (*,*) i, sin_d(x4), sin_d(x8), sin_d(x10)
end do
DO i=0,90,5
x4 = i
x8 = i
x10 = i
write (*,*) i, cos_d(x4), cos_d(x8), cos_d(x10)
end do
end
|
|
|
Back to top |
|
 |
|