An Algorithm for Calculating the Inverse Sine of a Given Value
Using Newton’s Method Iteration
Leo T. Meire
Because the Pbasic program does not support an inverse sine function, the calculation of the inverse sine of a given number a, where -1 <= a <= 1, requires development of an algorithm that can be translated into a Pbasic function.
Consider that the problem can be stated : Find the value of X such that X = arcsin(a).
Restate the problem as sin(X) = a (by taking the sine of both sides), and define a function f(X) = sin(X) - a = 0.
The problem is now to determine the value of X that makes this statement true.
Newton’s Method is an iterative formula for numeric determination of the “zeroes” of a differentiable function f(X), starting from an initial value X0 sufficiently close to the true value of X :
X1 = X0 - ( f(X0) / f ’ (X0) ), or, in general,
Xn+1 = Xn - ( f (Xn) / f ’ (Xn) ).
In this case we have defined f(X) = sin (X) - a, and so we can calculate
f ’ (X) = cos (X).
The iteration formula then becomes
X n+1 = Xn - ( (sin (Xn) - a) / cos(Xn) ).
The remaining part of the problem to be determined is the value of the “initial guess” X0. Because the sine function is “well behaved” - it does not have asymptotes and imaginary roots - a good initial value is X0 = a. In fact, for small values of a, this is very close to the true value of X. Both x and a must be expressed in radians; the arcsin function takes values between -pi/2 and pi/2 only (-90° to 90°).
Here is an example of a function written in Pascal to calculate the arcsin of a given value.
function arcsin(a:real):real;
{MUST have -1 < a < 1}
{Returns x = arcsin(a), using Newton’s Method}
var x:real;
const epsilon = 1.0E-7;
begin {arcsin}
x := a;
repeat x := x - (sin(x)-a)/cos(x) until (abs(sin(x)-a) <= epsilon);
arcsin := x;
end; {arcsin}
Again, note that the value of x returned is in radians,
-pi/2 <= x <= pi/2.
Here I have used a constant, epsilon, with a small value (1E-7) to determine when the value of X is sufficiently close to the true value that the iteration may be stopped. This value can be adjusted to converge to a sufficiently accurate value in a reasonable time.
The last remaining problem I can see in the translation of this algorithm to Pbasic is that language’s use of “two’s complement” arithmetic for negative values. Frankly, I have not given sufficient thought to the ramifications of this to be able to state in advance how it will affect the calculations. The easiest way to settle the matter is to code it up and run it. If it works for values of a near -1, 0, and 1, it is probably OK. I am not a Pbasic programmer, so I can’t say how best to do the translation, but I know that there are plenty of clever FIRST people out there. Let me know how it goes. Admittedly, using this method is somewhat like climbing down the chimney because the doors are locked, but at least it will get you in the house.