Computing exponentials and Trig functions

Fredrik Johansson fredrik.johansson at gmail.com
Thu Dec 6 18:00:38 CET 2007


On Dec 6, 2007 5:28 PM,  <mr.janus at mac.com> wrote:
> Hello,
>
> I'm trying to write a program in C using GMP as matlab is unable to handle the precision i need for solving my coupled equations accurately. However, one of the many problems i'm having is how to speed up the calculation of trig functions.
>
> I often have to solve complex exponentials but the way i have coded it is painfully slow. I split the exponential into the real and imaginary parts and solve separately. I then solve using sin, cos, sinh, and cosh identities.
>
> However the slowdown problem arises from my calculation of the trigonometric functions, which i do by Taylor expansion. Obviously, as I push the precision the Taylor expansion takes longer and longer to converge to the required precision. How does everyone else do this?
>
> Many thanks
>
> Huw

There are tricks for accelerating the convergence of Taylor series of
elementary functions. To begin with, if you want to calculate sin or
cos of a big number you should first reduce the argument modulo pi/2.
However, instead of going through the hard work of implementing the
functions yourself, you could just use MPFR (http://www.mpfr.org/).

Alternatively, if the precision you need is not too high, it might be
faster to use Chebyshev approximations than Taylor series.

Fredrik


More information about the gmp-discuss mailing list