Silverfrost Forums

Welcome to our forums

Syntax problem

27 Mar 2014 6:33 #13895

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(A2+B2) 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

27 Mar 2014 6:49 #13896

This code works on my PC:

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

27 Mar 2014 6:49 #13897

This code works on my PC:

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

27 Mar 2014 6:49 #13898

This code works on my PC:

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

27 Mar 2014 7:19 #13899

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,

T=A/C
X=asin(T) 
Y=acos(T)

Or even,

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.

27 Mar 2014 8:06 #13901

Linder and david thanks for all. Next time I will be careful with the units

Please login to reply.