Numerical Methods at work

Disclaimer:
Permission to use, copy, and distribute this software, and It’s documentation for any non-commercial purpose is hereby granted without fee, provided: THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL Henrik Vestermark, BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Taylor serie Explorer

This tool lets you explore numerical Taylor serie expansions of math functions (like sine, cosine, exp, logarithm, and hyperbolic functions etc.), compare them with built−in values, and generate error plots. You can add multiple input sets, automatically produce new plots for each, and then print a combined report containing both the data and the plotted results.

Taylor series Explorer vs. 1.0
Input 1










  • Infomation
  • Help
  • Error Plot 1

Taylor Series Explorer - User Guide

This web tool helps you approximate various mathematical functions (sin, cos, tan, exp, ln, sinh, cosh, tanh) using their Taylor series expansions. You can compare the Taylor-based result with the language's built-in function value and see how the approximation error behaves for different numbers of series terms or "argument reduction" options.

1. Choose a Function

  • In the first dropdown, select which function you want to approximate (e.g., sin(x), cos(x), etc.).
  • This determines how the tool calculates its Taylor series expansion.

2. Enter Number of Terms

  • In the No. of Taylor terms field, specify how many terms to sum in the series expansion (e.g., 5, 10).
  • The larger the number of terms, the more accurate the approximation should be, but with potentially higher computation.
  • If your tool supports an auto setting, you can leave this set to "auto" to let the software decide when to stop adding terms (e.g., when it no longer changes due to floating-point limits).

3. Set Argument Reduction

  • In the No. of Reduction field, you can specify how many times to reduce the function's input before computing the Taylor series. For instance, dividing by 3 repeatedly in a sin(x) approach, or halving for exp(x).
  • Reducing a large input often improves convergence of the series, then the final result is scaled back up with a known identity (e.g., triple-angle formula).
  • If set to auto, the tool will decide an appropriate number of reductions (e.g., until the input is below a certain threshold).

3. Set Reduce Period

  • In the Reduce Period checkbox field, you can specify whether to map trigonometric values into the interval closest to zero. For example, sin(x) values larger than π/2 can be mapped to the interval [0..π/2], improving accuracy and reducing the number of Taylor terms needed for an acceptable result.
  • Reducing large input values improves both the convergence and accuracy of the series.
  • If not selected, no mapping of x is performed, which results in reduced accuracy for large values.

4. Specify the Decimal Input (x)

  • The Decimal Number field is where you type in the value of x at which you want to evaluate the function's Taylor series.
  • For example, if you want sin(1.2), enter 1.2 here. The tool will compute the approximate value using your Taylor configuration, and also check Math.sin(1.2) to measure the error.
  • You can input mathematical expressions using the Math library's syntax. Examples include:
    • Basic arithmetic: 4.5*π/2, 2^3 + 5, 3.14159/4
    • Mathematical constants: π (pi), e (Euler's number)
    • Trigonometric inputs: 45 deg, π/6, 2*π
    • Combined expressions: (3+2)*π/4, 2*e^2 + 5
    • Scientific notation: 1.5e-3*π, 2.5e2/π
    The library automatically evaluates these expressions to their numerical values.

5. Add More Inputs (Optional)

  • Click the Add Input Field button to create an additional set of fields. Each new set has its own function, terms, reduction, and input x.
  • This lets you compare different functions side by side, or the same function with different term counts or reduction strategies.

6. Review Error Plots

  • Each new input set automatically creates a new Error Plot tab. Click on Error Plot #N in the tabbed interface to see the resulting graph.
  • These plots typically show how the error changes for varying numbers of terms, or how argument reduction affects accuracy.
  • Hover over the plot to see data points, or use built-in tools (zoom, pan, etc.) for a closer look.

7. View or Edit the Text Log

  • Inside the Infomation tab, there's a large Display area showing numerical results and error details for each computation.
  • You can add more lines to this log by adjusting inputs or re-computing new sets of data.
  • Use the Clear button to reset the log if needed.

8. Print or Email Your Results

  • Print: Click the Print button to open a new window containing all your text output (the log) plus any generated error plots. From there, you can print or save as PDF.
  • Email: Click the Email button to send the same report to an email address. The tool prompts you for the recipient address and then packages all the info (including textual analysis and images).

Taylor Series Formulas Used

sin(x)
\(\displaystyle \sin(x) \;=\; \sum_{k=0}^{\infty} (-1)^{\,k}\,\frac{x^{2k+1}}{(2k+1)!}\)
This can be extended with argument-reduction (e.g., dividing by 3) and the triple-angle formula: sin(3a) = 3 sin(a) - 4 sin³(a).
cos(x)
\(\displaystyle \cos(x) \;=\; \sum_{k=0}^{\infty} (-1)^{\,k}\,\frac{x^{2k}}{(2k)!}\)
Optionally uses the triple-angle identity cos(3a) = 4 cos³(a) - 3 cos(a) for re-scaling after reductions.
tan(x)
\(\displaystyle \tan(x)\;=\;\sum_{n=1}^{\infty} \bigl[(-1)^{\,n-1}\,2^{\,2n}\,\bigl(2^{\,2n}-1\bigr)\,B_{2n}\bigr]\;\frac{x^{\,2n-1}}{(2n)!}\)
Here, \(B_{2n}\) are Bernoulli numbers. Large \(x\) can be reduced, then scaled back with \(\tan(3a) = \frac{3\tan(a) - \tan^3(a)}{1 - 3\tan^2(a)}\).
exp(x)
\(\displaystyle e^x \;=\; \sum_{k=0}^{\infty} \frac{x^k}{k!}\)
If \(x\) is large, we can reduce by halving \(x\) repeatedly, compute \(e^{x/2^m}\), then square repeatedly.
ln(x)
For \(x>0\), we often use \(\displaystyle \ln(x)\;=\;2\,\Bigl(z + \frac{z^3}{3} + \frac{z^5}{5} + \dots\Bigr)\), where \(\displaystyle z=\frac{x - 1}{x + 1}\).
Additional "square root" reductions can be done: \(\ln(\sqrt{x}) = \tfrac12\ln(x)\).
sinh(x)
\(\displaystyle \sinh(x)\;=\;\sum_{k=0}^{\infty} \frac{x^{\,2k+1}}{(2k+1)!}\)
Argument reduction can be reversed with the triple-angle identity sinh(3a) = 3 sinh(a) + 4 sinh³(a).
cosh(x)
\(\displaystyle \cosh(x)\;=\;\sum_{k=0}^{\infty} \frac{x^{\,2k}}{(2k)!}\)
Uses cosh(3a) = 4 cosh³(a) - 3 cosh(a) for re-scaling if argument reduction is applied.
tanh(x)
\(\displaystyle \tanh(x)\;=\;\sum_{n=1}^{\infty} \frac{\,2^{2n}\,\bigl(2^{2n}-1\bigr)\,B_{2n}}{(2n)!}\;x^{2n-1}\)
With triple-angle expansion \(\tanh(3a) = \frac{3\tanh(a)+\tanh^3(a)}{1+3\tanh^2(a)}\) after reductions.

Each function can use an "argument reduction" step to shrink large inputs and then restore the final value via its respective angle identity. This approach can reduce the number of Taylor terms needed and improve numerical accuracy.

I hope this helps you understand how various functions' Taylor series expansions behave. If you have feedback or encounter any issues, please use the email me at hve@hvks.com or use the feedback link to let me know!



Corrections:
7-Jan-2025vs 1.0Initial release