Oleg Kobchenko wrote:

> In Elementary Functions, K.E.Iverson, 1966, there is a square root
> algorithm that can be translated with default tolerance like this
>
> sr=: 3 : 0
>   a=. c=. y
>   while. d=. * y-*:a do.
>     a=. a [EMAIL PROTECTED] c=. c%2
>   end.
> )
>    sr 5
> 2.23607
>

This is the bisection method.  Here's a modification to calculate arcsin:

sin=:1&o.
arcsin=:3 : 0
a=.0
c=.1r2p1
while. d=. * y.- sin a do.
 a=. a ] [EMAIL PROTECTED] c=.c%2
end.
)
  arcsin 0.5
0.523599
   _1&o. 0.5
0.523599

You need an interval [a-c,a+c] which initially brackets the root.  It will
then be linearly convergent: the error bound is given by c, and this
halves on each iteration.

The bisection method will always find a root, but it is slow.  Newton's
method needs the derivative of the function whose root you are trying to
find, but it will be quadratically convergent to a simple root if you
start close enough.

Best wishes,

John


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to