I have need to compute the functions: $$ f(x) = \frac{\sin^{-1}x}{x}$$ and $$ g(x) = \frac{\sin a x}{\sin x} $$ where $a\in[0,1]$ and $ x\in[0,\frac{\pi}{2}]$ and is often very small ($x\ll 1$). Are there any general ways of generating highly accurate algorithms for "special" functions like these?
|
Do a polynomial expansion (a la l'Hopital's rule) for both enumerator and denominator and you get a rational function that, for small $x$, will approximate the function well. As an example: $$ \frac{\sin ax}{\sin x} \approx \frac{ax-\tfrac 1{3!}(ax)^3 + \ldots}{x-\tfrac 1{3!}x^3 + \ldots} = \frac{a-\tfrac 1{3!}a^3x^2 + \ldots}{1-\tfrac 1{3!}x^2 + \ldots}. $$ You can do better if you have an idea of the range of values $x$ at which you want to evaluate. You can then replace the Taylor expansion around $x_0=0$ above by a better suited interpolation of projection approach for the range of $x$. |
||||
|
|
|
My approach is to use software like SymPy as follows:
which prints:
The first number is a Taylor series expansion truncated at 10 terms, the second number is the exact evaluation. SymPy uses exact arithmetic, in this example I used x = 1/100 and a = 1/2, but you can play with that. Finally, I evaluate it to 30 decimal digits so that one can easily compare the numbers. The third number is a double precision evaluation using Python's floats. In this case, it seems to me that there is no cancellation. But for other expressions the direct double precision evaluation might no be accurate enough and then series expansion is one way to evaluate it. The other is rational approximation, I have used |
|||
|
|