just remember.. if you have a sin() function implemented, you
simply write a macro to do cos() - using sin().
cos is 90 degrees out of phase from sin.
so..
cos(x) = sin(x+90) // in degrees
cos(x) = sin(x+PI/2) // in radians
az.
--
Aaron Ardiri
Lecturer http://www.hig.se/~ardiri/
University-College i G�vle mailto:[EMAIL PROTECTED]
SE 801 76 G�vle SWEDEN
Tel: +46 26 64 87 38 Fax: +46 26 64 87 88
Mob: +46 70 352 8192 A/H: +46 26 10 16 11
On Fri, 9 Apr 1999, Danko Radic wrote:
>
> Well, you should just specify the range of validity of your expansion.
> Expansion used in your routine
> 'Approximation is x - ( x**3 / 3! ) + ( x**5 / 5! ) - ( x**7 / 7! ) + ...'
> is valid only around x=0.
> Around some arbitrary value of x=a, you should make expansion
> sin(x)=sin(a)+(x-a)*sin'(x|x=a)/1!+(x-a)^2*sin''(x|x=a)/2!+...
> (where sin''(x|x=a) means second derivation of function sin(x) for x=a
> etc.)
>
> Here is a bit more specific Taylor series for sin(a+x):
>
>
>sin(a+x)=sin(a)+x*cos(a)-x^2*sin(a)/2!-x^3*cos(a)/3!+x^4*sin(a)/4!+...+x^n*sin(a+n*PI/2)/n!
>
> where you can specify values of sin(a) at the points of mesh (of
> wanted density - the finer, the better) in the table (proposed before)
> and then use expansion above to get values of sin() around that point.
>
> Analogy can be used for cos(x).
>
> Regards,
> Danko Radic
> Dept. of Physics
> University of Zagreb
> Croatia
> ------------------------------------------------------------
>
> On Thu, 8 Apr 1999, Creative Digital Publishing Inc. wrote:
>
> > >> I have been trying to use cosine and sine in my application.
> > >> I have tried to use math.h but this doesn't seem to be a palmfile.
> > >> Does anyone have a suggestion?
> >
> > Here's some code that's worked fine for me. Hope it helps.
> >
> > Regards,
> > Steve Mann
> >
> > # # #
> >
> > #define MINUS_ONE ( double ) -1.0
> > #define DEGS360_RADIANS 360.0 * DEGREES_TO_RADS
> > #define MAX_COS_ITERATIONS 10
> > #define MAX_SIN_ITERATIONS 10
> >
> > /*****************************************************
> > __sin
> >
> > Calculate the sin of a double radians angle.
> > Approximation is x - ( x**3 / 3! ) + ( x**5 / 5! ) - ( x**7 / 7! ) + ...
> > *****************************************************/
> >
> > double __sin ( double x ) {
> >
> > double result, numerator, denominator, term, sign, factorial, x1;
> > int cnt = 0;
> >
> > // scale input angle to proper range of values
> >
> > x1 = x;
> > while ( x1 > DEGS360_RADIANS ) {
> > x1 = x1 - DEGS360_RADIANS;
> > }
> >
> > // initialize everything
> >
> > result = x1;
> > numerator = x1;
> > denominator = ONE;
> > factorial = ONE;
> > sign = MINUS_ONE;
> >
> > for ( cnt = 0; cnt < MAX_SIN_ITERATIONS; cnt++ ) {
> >
> > // calculate the next term
> >
> > numerator = numerator * x1 * x1;
> > denominator = denominator * ( factorial + ONE ) * (
> > factorial + TWO );
> > term = numerator / denominator;
> > result = result + ( sign * term ) ;
> >
> > // prepare for next sequence thru loop
> >
> > sign = sign * MINUS_ONE;
> > factorial = factorial + TWO;
> > }
> >
> > return result;
> > }
> >
> >
> > /*****************************************************
> > __cos
> >
> > Calculate the cos of a double radians angle
> > Approximation is 1 - ( x**2 / 2! ) + ( x**4 / 4! ) - ( x**6 / 6! ) + .....
> > *****************************************************/
> >
> > double __cos ( double x ) {
> >
> > double result, numerator, denominator, term, sign, factorial, x1;
> > int cnt = 0;
> >
> >
> > // scale input angle to proper range of values
> >
> > x1 = x;
> > while ( x1 > DEGS360_RADIANS ) {
> > x1 = x1 - DEGS360_RADIANS;
> > }
> >
> > // initialize everything
> >
> > result = ONE;
> > numerator = x1 * x1;
> > denominator = TWO;
> > factorial = TWO;
> > sign = MINUS_ONE;
> >
> > for ( cnt = 0; cnt < MAX_COS_ITERATIONS; cnt++ ) {
> >
> > // calculate the next term
> >
> > term = numerator / denominator;
> > result = result + ( sign * term ) ;
> >
> > // prepare for next sequence thru loop
> >
> > numerator = numerator * x1 * x1;
> > denominator= denominator * ( factorial + ONE ) * (
> > factorial + TWO );
> > factorial = factorial + TWO;
> > sign = -sign;
> > }
> >
> > return result;
> > }
> >
> > -------------------------------------------
> > Creative Digital Publishing Inc.
> > 1317 Palm Street, San Luis Obispo, CA 93401-3117
> > -------------------------------------------
> > 805.788.0138 805.593.3811 (fax)
> > [EMAIL PROTECTED] http://www.cdpubs.com
> >
> >
> >
> >
>
>
>