Go to Post Only a few more days till i get to see her again! This is sad you would think I was talking about a chick... no wonder my gf gets jealous. XD - sportzkrazzy [more]
Home
Go Back   Chief Delphi > Technical > Technical Discussion
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 24-10-2001, 11:00
Happy Birthday! Leo M Leo M is offline
Registered User
#0384 (Tucker Tigers)
 
Join Date: Jun 2001
Location: Richmond, VA
Posts: 70
Leo M is just really niceLeo M is just really niceLeo M is just really niceLeo M is just really niceLeo M is just really nice
Arcsin Calculation Algorithm

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.
__________________
Leo M.

Last edited by Leo M : 25-10-2001 at 07:39.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
gearing design calculation question caffel Motors 4 24-03-2003 17:34
Motor Calculation Spreadsheet MrB Motors 0 16-02-2002 07:14


All times are GMT -5. The time now is 04:40.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi