In many cases it is useful to analyze instead of a function a series that approximates it. This is true especially, if the series converges to the function without restrictions. Then the partial sums of the series can be considered as approximations with increasing accuracy.
For the terms of the sequence that make up the series one will use preferably such functions, that can be differentiated and integrated easily. Especially suitable are series, whose terms are powers or trigonometric functions of the variables. The first case leads to the Taylor series, whose coefficients are obtained via differentiation, which we will study more closely in the following. The second case leads to the Fourier series, which we will visualize after treating the integral, since its coefficients are determined via integration.
Another argument for the choice of a particular series expansion can be, to use functions for the terms of the series, that are particularly adapted to the symmetry of the problem that is described by the function, i.e Bessel functions for cylindrical symmetry and spherical harmonics for point symmetry.
The Taylor series is an infinite series, whose partial sums are an approximation for the function y=f(x), that is exact at the point and approximate in the vicinity of and the interval for an acceptable approximation becomes larger with increasing index of the partial sum. Then the members of the sequence that constitutes the series are powers of the distance from the computation point . Thus the function is approximated via a power series and the problem consists of finding the coefficients of the individual terms.
To achieve this we first equate the function formally to a power series with terms and parameters . Then we differentiate both sides repeatedly. After each step we put . Thus all powers containing drop out from the power series for the respective derivatives and the coefficient of the remaining term can be easily obtained:
Thus the coefficient of the -th power is proportional to the -th derivative of the function at the computation point and the factorial as a factor simply follows from the differentiating the -th power. The Taylor series of the function is then with 0!=1,1!=1 and :
While f’(x)=df/dx(x) describes the slope of a differentiable function at each point in its domain of definition, i.e. describes the slope of the slope or the change of the slope of . The slope changes if and only if the curve has a curvature. Therefore is a measure of the curvature of . If one identifies with the time and y=f(t) with the distance traveled by an object during the time , the first derivative is denoted by velocity and the second derivative is called acceleration of the object that is at time at position .
The first approximation of the Taylor series takes into account the slope of the function at the computation point, the second one in addition its curvature. The higher approximations use higher derivatives and it makes sense to also visualize their meaning.
In the simulation of Fig5.1 the derivatives up to the 9-th order are calculated for a function that can be chosen from 9 given options and are shown as coloured curves in a abscissa region that depends on the function and also may have a shifted origin. With the choice boxes on top the derivatives to be plotted in addition to the function can be selected, all 9 are shown in the picture. For the red point that can be moved with the mouse the values of the local values of the derivatives are calculated anew and display in the number fields on the left.
The derivatives are approximated numerically as differential quotients using both neighboring points:
You will find further details about this in the description pages of the simulation. Parser
In many simulations contained in this book it is possible to enter formulas for functions directly in mathematical notation. For the program the functions are initially strings without meaning, that have to be interpreted by an additional program, a parser and translated to Java code. This is a relatively complex process. If the function is only translated once for a simulation the required time is not of concern and one has, when using the parser for EJS, the advantage of being able to change the function or enter a new one without having to open and edit the program itself.
The determination of the higher derivatives with sufficient accuracy requires a considerable computational effort. In the example of Fig5.1 the function has to be evaluated 10 000 times for one computation, which puts a strain on the computing speed of a simple PC. Therefore the functions are predetermined in our example. If you want to analyze other functions you may open the simulation with EJS console and change the simple Java code of the preset functions.
In the upcoming simulations of Fig5.2 and Fig5.3 the approximations for the derivatives are calculated once without and once with using the parser and you will recognize the difference in the computation speed from these examples.
Convergence of the Taylor series
It should not be taken for granted, that the power series approaches the function also for values of outside of the computation point . During the discussion of the exponential function, which has as a power series a large similarity with the Taylor series, we had however already established that the series also has to converge within the vicinity of the computation point if the factors attached to its term do not diverge. For the Taylor series these factors are the derivatives in the computation point. If the function can be differentiated as many times as desired , the Taylor series converges for all values of the variable This condition includes, that the derivatives at the computation point are bounded: the -th derivatives grow slower than .
For many functions that are important in Physics, as for example polynomials, exponential function, sine and cosine the domain of convergence is unlimited. With increasing order or number of terms the corresponding Taylor series approximates the original function over a larger and larger interval and the domain of small deviations becomes larger and larger. In practice one normally use a partial sum of finite order; then the partial sum is identical to the function at the point of computation and increasingly deviates from the function with growing distance from it.
It is amusing to ask for the Taylor series of the exponential function. Since all it derivatives are equal the Taylor series coincides with the exponential series.
The power function of degree has non-vanishing derivatives only up to order . In this case the Taylor series terminates after the -st term. Its Taylor expansion is thus identical to the original function.
The trigonometric functions however have a unlimited number of derivatives that are repeated periodically, for example sin x, cos x, -sin x, cos x, sin x…. The approximation will become the better the more terms of the series expansion are retained.
Among the possible approximation functions the Taylor series is characterized via the fact, that the coefficients can be determined from data at computation point alone, namely all the derivatives of the function as this point. This series has the large practical advantage, that its terms are powers and can therefore be easily added to and multiplied with each other and also easily integrated and differentiated; the derivatives of the function at the computation point that appear in the coefficients are constants for the above listed operations listed above. Therefore in the physical analysis complex functions are often approximated by a Taylor series with a limited number of terms: linear approximation with two terms and quadratic approximation with three terms.
The linear term of the Taylor series already yields approximations that are often used in practice: for three basic functions the derivation is show; for other cases you may easily derive this your self. You may for example use for the computation point and determine the next higher derivative.
Using the Taylor series one can quickly obtain formulas for the calculation of the first derivative . This also yields a measure for the respective accuracy. We show this for the linear approximation; the procedure can be easily extended to higher approximations.
We assume in the following, that both and are known.
In the last line is the usual definition for the difference quotient supplemented by the term O(x)(letter O), which gives the deviation from the differential quotient due to neglecting the higher terms of the Taylor series. The deviation vanishes in the limit of , since all terms contained in depend at least linearly on . For sufficiently small intervals the higher powers of can be neglected against the linear term and one obtains the important conclusion, that the procedure of differentiation according to the above formula becomes accurate linearly with . If one halves the width of the interval the accuracy is doubled.
Using the Taylor series one can easily derive a method with better convergence for the calculation of the derivative. We write down the Taylor series once for a point that is to the right of the computation point and once for a point that is to the left of the computation point. Subtracting the two series from each other the terms with even powers drop out:
The formula obtained in this way converges quadratically with the width of the interval; halving the interval improves the accuracy by a factor 4.
One can continue with the above procedure and thus obtain even faster converging approximation formulas; however one then needs values of the function at more points to calculate the differential quotient. Therefore one often sticks to the above approximation with quadratic convergence.
In the following we consider two simulations to visualize Taylor expansions. The first in Fig5.2 uses the same setup, that was employed for the calculation of derivatives up to 9-th order in Fig5.1. The formulas for the preset functions cannot be edited. The speed of computation is so large, that the approximating polynomial reacts to moving the computation point with the mouse quasi in real time.
The figure shows the 9-th approximation for the Gauss function, which can be selected with the choice boxes above. In the number fields we now have the coefficients of the Taylor series. They only differ from the values of the derivatives via the factor for the order .
In the following simulation of Fig5.3 a parser is used to evaluate the function that can be edited. Using this simulation you can study the Taylor expansion for arbitrary functions albeit at a slower speed of computation. Here the highest order is limited to .
The Taylor approximation of the red function is shown in blue and the deviation is plotted in green. Fig5.3 shows a Gaussian function with the third approximation in the vicinity of the computation point that is drawn in magenta and can be pulled with the mouse along the function. With the keys +1 and -1 the approximation order can be increased and decreased.
This simulation allows for many possible experiments. In the selection field for functions a number of standard functions can be selected (sine, exponential function, power function, Gaussian, hyperbolic functions, sin(x)). They contain up to three parameters and can be edited. You also can enter an arbitrary analytical function for the computation.
Using a parser for the evaluation of the editable function slows down the computation considerably. Depending on the configuration of your computer it can take up to a few minutes until the result for the seventh approximation appears.
After opening the simulation you first call a function from the selection list for which initially the third approximation is calculated for a computation point of . Then you can move the computation point and change parameters, and the result is still shown practically in real time for the third approximation. The description pages of the simulation contain further details and suggestion for experiments that can be done.