Page 1 of 1

Arccos function

Posted: Mon Sep 28, 2009 4:25 am
by Eleftheria Pissadaki
Dear Forum,

I am looking for the arccos function, any suggestions?

Thanks in advance,

Eleftheria

Re: Arccos function

Posted: Tue Sep 29, 2009 9:42 am
by ted
atan is built in. If you need arccos, you can write your own using atan.

Re: Arccos function

Posted: Tue Sep 29, 2009 1:48 pm
by Eleftheria Pissadaki
Thank you very much Ted, for the record this is the function I used:

Code: Select all

func acos() {
   denom = 1 - $1 * $1
   if (denom == 0.0) {
       return PI/2
   } else{
       return PI/2 - atan($1 / sqrt(denom))
    }
}
Moderator's note: message edited to insert code markup.

Re: Arccos function

Posted: Wed Sep 30, 2009 4:04 pm
by ted
I think you meant this:

Code: Select all

func acos() {
  if ($1==0) {
    return PI/2
  } else {
    return atan(sqrt(1-$1^2)/$1)
  }
}