replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Trigonometric Functions COS and SIN.
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Trigonometric Functions COS and SIN.

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Jim



Joined: 21 Jul 2006
Posts: 24
Location: USA

PostPosted: Mon Oct 31, 2011 1:17 pm    Post subject: Trigonometric Functions COS and SIN. Reply with quote

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
View user's profile Send private message
brucebowler
Guest





PostPosted: Mon Oct 31, 2011 1:53 pm    Post subject: Reply with quote

Are INC specified in degrees or radians?
Back to top
Jim



Joined: 21 Jul 2006
Posts: 24
Location: USA

PostPosted: Mon Oct 31, 2011 2:35 pm    Post subject: Trig functions. Reply with quote

Specified in degrees.
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Mon Oct 31, 2011 3:56 pm    Post subject: Reply with quote

Trig functions in fortran use radians not degrees.
_________________
John Horspool
Roshaz Software Ltd.
Gloucestershire
Back to top
View user's profile Send private message Visit poster's website
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: D�sseldorf, Germany

PostPosted: Mon Oct 31, 2011 4:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 1899

PostPosted: Mon Oct 31, 2011 6:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
ebarbero



Joined: 01 Aug 2012
Posts: 20

PostPosted: Sat Aug 18, 2012 9:37 pm    Post subject: cosd, sind Reply with quote

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
View user's profile Send private message Visit poster's website
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2402
Location: Yateley, Hants, UK

PostPosted: Sun Aug 19, 2012 10:25 am    Post subject: Reply with quote

... 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
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Mon Aug 20, 2012 4:51 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group