Polynomial approximation

About this lesson plan

This is a lesson plan for indented for realization during 2h lesson activities.

It has been developed during work in iCSE4school project based on lesson carried out in 2015-2017 at The Stefan Batory High School in Chorzów.

It was prepared by Krzysztof Jarczewski based on his lesson.

Attention!

In each of the “code” cells you can change any number, text or instruction. In order to return to the original version refresh the webpage. Sometimes the next code depends on variables defined from the previous one, so one has to execute cells in order of apperance.

Factorial

The factorial of a integer n , denoted by n !, is the product of all positive integers smaller than or equal n.

\[\begin{split}\left\{ \begin{array}{ll} 0!=1 & {} \\ n!=n \cdot (n-1)!, & {} n>0 \\ \end{array} \right.\end{split}\]

For example,

\[\ 4!= 4 \cdot 3! =...= 4 \cdot 3 \cdot 2 \cdot 1 \cdot 1 = 24\]

The factorial in SageMath.

The first example counts factorial according to the definition.

The second example uses a built-in function in SageMath.

Derivative

Derivative will be interpreted as a mathematical operation on a function.

Basic formulas:

\[\begin{split}\begin{array}{ll} n'=0 \\ x'=1 \\ (x^n)'= n \cdot x^{n-1}, & {} n>1 \\ (sin(x))'=cos(x) \\ (cos(x))'=-sin(x) \end{array}\end{split}\]

The following examples in Sage with operation diff.

Next formulas for the derivative.

The following formulas for the derivative of the sum, difference, product and quotient of functions.

\[\begin{split}\begin{array}{ll} f, g - functions, \hspace{1cm} c - real \hspace{0,2cm} number\\ (c \cdot f)' =c \cdot f' \\ (f+g)'= f' + g' \\ (f-g)'= f' - g' \\ (f \cdot g)' = f' \cdot g + f \cdot g' \\ (f/g)'= (f' \cdot g - f \cdot g')/g^2 \end{array}\end{split}\]

Comments

The number before the variable does not change operations on the derivative.

Algebraic expressions separated by + or count separately.

Examples

\[\begin{split}\begin{array}{ll} (c \cdot f)' =c \cdot f' \\ (f+g)'= f' + g' \\ (f-g)'= f' - g' \end{array}\end{split}\]
\[(f \cdot g)' = f' \cdot g + f \cdot g'\]
\[(f \cdot g)' = f' \cdot g + f \cdot g'\]

Derivatives of derivatives - Derivatives of higher orders.

We can calculate the derivative of a derivative.

Derivatives of higher orders are written in the following way:

\[\begin{split}f''(x) , \hspace{1,1cm} f'''(x) , \hspace{1,1cm} f''''(x),\hspace{1cm}... \\ f^{(2)}(x) , \hspace{1cm} f^{(3)}(x) , \hspace{1cm} f^{(4)}(x),\hspace{1cm}...\end{split}\]

Below, the calculations of higher order derivatives of the SageMath:

Calculating the value of the derivative at the point.

Derivative of a function is a function so we can calculate the value of the derivative for the argument.

Below suitable examples.

Polynomial.

Polynomial of n degree and x variable is called function:

\[W(x)=a_0+a_1 \cdot x +a_2 \cdot x^2 +...+a_n \cdot x^n, \hspace{1cm} a_0, a_1, a_2, ..., a_n - coefficients.\]

Conclusion

Linear function and quadratic function are polynomial.

\[\begin{split}\begin{array}{ll} W_1(x)=a_0+a_1 \cdot x \\ W_2(x)=a_0+a_1 \cdot x +a_2 \cdot x^2 \end{array}\end{split}\]

Line.

We know are line goes through two points. Besides, knowing the coordinates of the points above, we can determine the formula of this line. We should remember that the formula is a linear function:

\[y = a x + b\]

Directional factor and the intercept can be calculated from these formulas:

\[\begin{split}a=\frac{y_2-y_1}{x_2-x_1} \\ b=y_1-ax_1\end{split}\]

Typing the appropriate equations, we can draw a straight line through two points.

Parabola.

Below, there is an example for three points which are not collinear. Then we can determine the quadratic function, which includes these points. So we have to determine a, b, c coefficients from the following equation quadratic function.

\[\begin{split}\begin{cases} y_1=ax_1^2+bx_1+c \\ y_2=ax_2^2+bx_2+c \\ y_3=ax_3^2+bx_3+c \end{cases}\end{split}\]

This work is tedious, even for a specific example. If we wanted to determine appropriate models as above for the linear function that probably it would probably take us a long time.

Below we use the capabilities of Sage.

We calculate the following equations, where he search coefficients: a, b, c.

\[\begin{split}\begin{cases} y_1=ax_1^2+bx_1+c \\ y_2=ax_2^2+bx_2+c \\ y_3=ax_3^2+bx_3+c \end{cases}\end{split}\]

Change the above system of equations for the corresponding matrix equation.

\[\begin{split}\begin{bmatrix} x_1^2&x_1&1\\x_2^2&x_2&1\\ x_3^2&x_3&1 \end{bmatrix} \begin{bmatrix} a\\b\\c\end{bmatrix} = \begin{bmatrix} y_1\\y_2\\y_3\end{bmatrix}\end{split}\]

In the SageMath we can easily solve this equation is enough to apply the following operation:

\[M v, \hspace{3mm} where \hspace{3mm} M-matrix, \hspace{0.3cm} v-vector \hspace{0.3cm} [y1, y2, y3]\]

Polynomial.

Here is an example for a few random points. The resulting function is a polynomial.

If you specify n points, it certainly passes through these points a polynomial of degree less than n.

For the random points calculate polynomial coefficients.

We draw a polynomial that goes passes through the given points.

Taylor’s formula.

From the mathematical analysis is known below the following formula is known. It approximates any function corresponding polynomial.

Taylor’s formula

\[\begin{aligned} f(x)=f(a)+{\frac {x-a}{1!}}f^{{(1)}}(a)+{\frac {(x-a)^{2}}{2!}}f^{{(2)}}(a)+\ldots + {\frac {(x-a)^{n}}{n!}}f^{{(n)}}(a)+\ldots \end{aligned}\]

We can simplify the above formula substituting for a = 0. We get The Taylor-Maclaurin formula.

\[\begin{aligned} f(x)&=f(0)+{\frac {x}{1!}}f^{{(1)}}(0)+{\frac {x^{2}}{2!}}f^{{(2)}}(0)+\ldots + {\frac {x^{n}}{n!}}f^{{(n)}}(0)+\ldots \end{aligned}\]

Here is an example for the function \(f(x)=sin(x)\).

Exercise for students.

For the function \(f(x)=cos(x)\) find the corresponding polynomial formula of Taylor-Maclaurin.

Use the Taylor-Maclaurin’s formula for function \(f(x)=e^x\).

We already know the Taylor’s formula. Now we can simplify our calculations, and use the built-in Taylor’s formula in SageMath.