Error in condition in Fortran

Asked

Viewed 43 times

0

Because the code:

    program acosseno
    implicit double precision(a-h,o-z)
PARAMETER(n=5)
    dimension x(n)
    dimension y(n)


alfa=0.6D0
k1 = 3
k2 = 5

print *, "Alfa is: ", alfa

open(1,file='a.dat') 


    x(1) = 5.0d0
x(2) = 10.0d0
x(3) = 2.0d0
x(4) = 20.0d0
x(5) = 30.0d0
y(1) = 1.0d0
y(2) = 3.0d0
y(3) = 15.0d0
y(4) = 8.0d0
y(5) = 35.0d0

do 1 i=1,n
    do 2 j = 1,n

if(i.ne.j)then
bi = sqrt(x(i)*x(i)+y(i)*y(i))
    bj = sqrt(x(j)*x(j)+y(j)*y(j))
ct = (x(i)*x(j)+y(i)*y(j))/(bi*bj)
endif

ang = acos(ct)  

    if(ang.le.alfa) goto 50 
    if(ang.gt.alfa) goto 60 

2       continue

50      print *, "le:", ang !ax = ang + k1 
60  print *, "gt:", ang !bx = ang + k2

    write(1,*)ax,bx

1       continue
    stop
        end

generates the following output:

 Alfa is:   0.59999999999999998     
 gt:   1.5707963267948966     
 le:   9.4061234627986545E-002
 gt:   9.4061234627986545E-002
 gt:   1.2408492346483417     
 le:  0.18311081726248352     
 gt:  0.18311081726248352     
 gt:  0.66477449481734552

Because for the same value (9.4061234627986545E-002) it is at the same time larger and equal to alpha? Other values are wrong too.

  • 2

    As in the case of le instruction labelled with 50, execution and the next instruction labelled 60 are performed. I am not Portuguese speaking, so the translation is through Google Translator. (As in case of le the statement labeled with 50 is executed and next the statement with label 60 is executed. I’m non Portuguese speaking so Translation is through Google Translate.)

  • Very good! Thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.