Search code examples
basic

translating a Basic program; stuck on ^(-1/2) and ^(3/2)


I am trying to translate a BASIC program. It has been many decades since I did any BASIC programming. :)

I am having a problem with 2 lines of code:

360 D=D+((X(I)-X(J))^2+(Y(I)-Y(J))^2+(Z(I)-Z(J))^2)^(-1/2)

510 F=((X(I)-X(J))^2+(Y(I)-Y(J))^2+(Z(I)-Z(J))^2)^(3/2)

x(i) etc form (x,y,z) coordinates; so line 360 is - I think - calculating the distance between 2 points; that would work if ^(-1/2) = square-root.

Line 510 is very similar, but the ^(3/2) has me stumped. Is it sensible to raise a number to the power of 1.5?

I remember that ^2 means square (aka raise to the power 2). So, can someone please tell me what ^(-1/2) and ^(3/2) mean in BASIC!?

Thanks for you help. Steve.


Solution

  • In BASIC the following is true:

    360 D = D + ((X(I) - X(J)) ^ 2 + (Y(I) - Y(J)) ^ 2 + (Z(I) - Z(J)) ^ 2) ^ (-1 / 2)
    361 D = D + 1 / SQR((X(I) - X(J)) ^ 2 + (Y(I) - Y(J)) ^ 2 + (Z(I) - Z(J)) ^ 2)
    
    510 F = ((X(I) - X(J)) ^ 2 + (Y(I) - Y(J)) ^ 2 + (Z(I) - Z(J)) ^ 2) ^ (3 / 2)
    511 F = SQR(((X(I) - X(J)) ^ 2 + (Y(I) - Y(J)) ^ 2 + (Z(I) - Z(J)) ^ 2) ^ 3)