1. arccos function
- Posted by Lee woo seob <wslee at HHI.CO.KR> Sep 25, 1997
- 838 views
Hi all! "arccos" function needs desperately to me (i am making a kind of engineering programs), and i don't know how to make it yet. i came to know that the arccos can be calculated by following formula, arccos(object x) = -arctan(x/sqrt(1-x*x)) + Pi/2 however, in case of x=1 or -1, this formula cause "zero divide error". i searched euphoria homepage (user contribution) and found the codes for "arccos", but, it accepts only atom value as x, not sequences... is there anyone to be able to make neat "arccos" function which accept both the atom and sequences? Bye! from -Lee woo seob...
2. Re: arccos function
- Posted by "Carl R. White" <crwhite at COMP.BRADX.XAC.UK> Sep 25, 1997
- 802 views
On Thu, 25 Sep 1997, Lee woo seob wrote: > Hi all! > > "arccos" function needs desperately to me (i am making a kind of engineering > programs), and i don't know how to make it yet. > > i came to know that the arccos can be calculated by following formula, > > arccos(object x) = -arctan(x/sqrt(1-x*x)) + Pi/2 > > however, in case of x=1 or -1, this formula cause "zero divide error". i > searched euphoria homepage (user contribution) and found the codes > for "arccos", but, it accepts only atom value as x, not sequences... > > is there anyone to be able to make neat "arccos" function which accept > both the atom and sequences? Whether it is or not, that looks like part of my mathbag.e. Could you tell me? :) You might like to trap values of 1 and -1 to avoid the error. procedure arccos(object x) if abs(x) > 0.9999999999 then -- this assumes you are using mathbag.e if x < 0 then return Pi else return 0 end if else return -arctan(x/sqrt(1-x*x)) + Pi/2 end if end procedure I think you'll find too that arcsin will have similar errors. Mathbag.e (if that's what you're using) will be updated as soon as I have time (probably Christmas ). -- Carl R White | e-mail...: crwhite- at -comp.brad.ac.uk | finger...: crwhite- at -dcsun1.comp.brad.ac.uk | web......: http://www.student.comp.brad.ac.uk/~crwhite/ Anti-Spam: Remove x's from header and change '- at -' to '@' in .sig
3. Re: arccos function
- Posted by Lee woo seob <wslee at HHI.CO.KR> Sep 29, 1997
- 773 views
Carl R. White wrote: >> >> arccos(object x) = -arctan(x/sqrt(1-x*x)) + Pi/2 >> > >Whether it is or not, that looks like part of my mathbag.e. Could you >tell me? :) Yes! the formula above came from mathbag.e. Sorry not to metion your name. Now, i come to know who prepared this nice routine! > >You might like to trap values of 1 and -1 to avoid the error. > >procedure arccos(object x) > if abs(x) > 0.9999999999 then -- this assumes you are using mathbag.e > if x < 0 then > return Pi > else > return 0 > end if > else > return -arctan(x/sqrt(1-x*x)) + Pi/2 > end if >end procedure > Your codes above can be used only when x is atom, not sequences. If the sequence is transferred to the above codes, i think it cause error. Euphoria built-in "arctan" accepts any sequence structure as well as atom. I think some "recursive" technique may be required to get universal version of arccos which accepts both the atom and sequences... i think, there may exists some 'general' or 'universal' codes structure to expand the individual calculation for atom, to any sequence structure... Bye... from Lee woo seob...