3
$\begingroup$

I'm trying to code the Taylor summation in MATLAB, being Taylor's formula the following:

Taylor summation

I've also seen $a$ denoted as $x_0$ in distinct bibliography.

Problem is that I'm not sure how should I evaluate or assign for $a$.

At lecture I studied the exponential Taylor's representation being: Taylor for exponential function

And I got to that same summation by evaluating $a$ as 0 but and I know that is meant to be McLaurin formula, but what's within evaluating with a different value or letting $a=x$?

What should I do in order to code properly Taylor summation for distinct functions?

$\endgroup$
2
  • $\begingroup$ $a$ is the point you approximate the function at. $\endgroup$ Jan 26, 2014 at 9:09
  • $\begingroup$ suppose that you have given $f(x)=\sqrt{x^2+300*x+400}$ and you want to compute $f(5)$,but can't do it by inserting,so you are approximating function using Taylor series at point $x=5$,in this case $a=5$ $\endgroup$ Jan 26, 2014 at 9:21

5 Answers 5

4
$\begingroup$

Any time you write use Taylor's formula to write a power series for a function, you must choose a point (of the domain) at which to evaluate the derivatives of the function. This point is called $a$. If the special choice $a=0$ is made, this yields Maclaurin's formula.

It is "gibberish" to set $a \leftarrow x$ since $a$ really is a constant for a given Taylor expansion and $x$ really is a variable. You can, however, have a Taylor series (some infinite polynomial in $x$) and then make the substitution $x \rightarrow a$ and find out the value of $f(a)$ since all the derivative terms are multiplied by powers of zero in the series.

For your coding, make a function which I here call "Taylor" and you should call something better. The simplest form of Taylor() takes the arguments $f$, $a$, $n$, $x$. Taylor() then computes the 0th through n-th derivative of $f$ at $a$, then evaluates Taylor's formula for the finite set of summation indices 1..n, returning the result. The following are improvements:

  • Don't supply an $x$ and get back an object which has precomputed the $n+1$ coefficients and has an operator() or "evaluate" public member function that can do the finite sum using a supplied value of $x$.

  • Arrange for whatever function actually does the final numerical sum to sort its arguments and sum from smaller in magnitude to larger in magnitude to control intermediate precision loss.

  • Don't supply an $n$ or the $x$ but do supply a precision argument. The function that does the summing now needs to have a way to estimate the residual of the Taylor series (which means your $f$ has to be able to tell you how big its next derivative can be anywhere in some interval) and then set $n$ so that the residual will be less than the precision argument when evaluated at $x$.

  • Construct function objects that just know their derivatives for any value of $a$. Numerically calculating the derivatives and then Taylor summing is horribly unstable.

  • Extend your numerical system to include "common numbers" like $\sqrt{2}$, $\sqrt{a}$ and the like. Let your system pass weighted sums of these numbers around and then only reduce them to floating point at the last possible moment. This will preserve significantly more accuracy. (I.e., a result can be of the form $0.0167889 + 45.6 \sqrt{2} + 6. \sqrt{a}$ and only reduce this to a floating point number at the last possible time.

  • Extend your numerical system to work with arbitrary symbolic expressions. Add a facility for simplifying these expressions so that the intermediate expression swell doesn't consume all available memory. Add a facility for computing the resulting approximations to arbitrary precision. (At this point, you've implemented quite a hunk of a computer algebra system...)

$\endgroup$
3
$\begingroup$

Given $a \in \mathbb R$, if $f$ is sufficiently well-behaved about $a$ it has a Taylor expansion about the point $a$. The coefficients you get will be different for each $a$.

The example you give is the Taylor expansion of $f(x)=e^x$ about the point $0$. If we expand it about the point (say) $\pi$, we get the equally valid series:

$$e^x = \sum_0^{\infty}\frac{e^{\pi}}{n!}(x-\pi)^n$$

$\endgroup$
2
$\begingroup$

$a$ is the point for which you calculate the derivatives that you plug in the expansion, along with the displacement from $a$ raised to the correct power, as you seem to understand yourself

$\endgroup$
2
$\begingroup$

Taylor series approximates given function at some point,in your case if we have given some function $f(x)$ and we can't compute exact value of this function at point $x=a$, we are trying to approximate it using derivatives at given point $x=a$,so in short this is a point where we want to compute function value

$\endgroup$
1
$\begingroup$

$a$ is any complex$^*$ quantity you want, so long as it is independent of $x$ and $n$. If you're writing a generic "evaluate a Taylor polynomial" function, you'll probably want to accept $a$ as input from a user rather than supply a value yourself.

There are two typical reasons to pick any particular value of $a$:

  • Your choice of $a$ makes it easy to obtain the values $f^{(n)}(a)$, and/or it simplifies those values
  • You want to evaluate it at $x$'s in some range, and you choose $a$ to keep the value $x-a$ small over that range, so that most of the value of the function comes from the first few terms of the sum

*: Actually, you can even do things in more generality than the complexes!

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .