|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Estanislao
Joined: 19 Jun 2013 Posts: 3 Location: Spain
|
Posted: Thu Mar 27, 2014 7:33 pm Post subject: Syntax problem |
|
|
Hi everyone,
I was refreshing FORTRAN 95 and I had a problem with SIN and ASIN. I think both problems are related
The first problem is when I try to calculate the sin 45(radians). The calculator gives me 0.70 while Plato gives 0.85.
The other problem is with ASIN. My program does not calculate the ASIN. This is my program:
PROGRAM cap1_7
IMPLICIT NONE
REAL :: A,B,S,pi,C
REAL :: X,Y,T
WRITE(*,*)'Sides of a triangle (m)'
READ(*,*)A,B
pi=3.1416
S=A*B
C=SQRT(A**2+B**2)
T=A/C
X=ASIN(T)
Y=(180-90+X)
PRINT*, 'hypotenuse',C,'m'
PRINT*, 'Area of rectangle',S,'m'
PRINT*, 'Triangle angles',X,Y,'Radians'
END PROGRAM cap1_7
Thanks in advance |
|
Back to top |
|
|
Wilfried Linder
Joined: 14 Nov 2007 Posts: 314 Location: Düsseldorf, Germany
|
Posted: Thu Mar 27, 2014 7:49 pm Post subject: |
|
|
This code works on my PC:
Code: | PROGRAM cap1_7
IMPLICIT NONE
REAL :: A,B,S,pi,rho,C
REAL :: X,Y,T
WRITE(*,*)'kathedes of a triangle (m)'
READ(*,*)A,B
pi = 4.D0*datan(1.D0)
rho = 45.D0/datan(1.D0)
S=A*B/2.D0
C=SQRT(A**2+B**2)
T=A/C
X=asin(T)
Y=(pi/2.D0-X)
PRINT*, 'hypotenuse',C,'m'
PRINT*, 'Area of triangle',S,'m²'
PRINT*, 'Triangle angles',X,Y,'Radians'
PRINT*, 'Triangle angles',X*rho,Y*rho,'degrees'
end
|
Regards - Wilfried |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Mar 27, 2014 8:19 pm Post subject: |
|
|
First of all SIN 45 degrees = 0.70 and SIN 45 radians = 0.85 (approx).
Therefore you probably have your calculator in degrees mode, not radians.
And second, in your code X is one of the angles in the triangle and is in radians, the other angle Y should be obtained by Y = (3.14159/2.0) - X. That is subtract from PI/2 not from 90 degrees (also you have Y = 90 + X so there is also the wrong sign in there!).
Or use,
Code: |
T=A/C
X=asin(T)
Y=acos(T)
|
Or even,
Code: |
X=atan(A/B)
Y=atan(B/A)
|
Its always a good idea to think about your units while programming. Better change that area to metres-squared as well. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
Estanislao
Joined: 19 Jun 2013 Posts: 3 Location: Spain
|
Posted: Thu Mar 27, 2014 9:06 pm Post subject: |
|
|
Linder and david thanks for all. Next time I will be careful with the units |
|
Back to top |
|
|
|
|
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
|