CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
calculuslab

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: calculuslab/Calculus_Lab
Path: blob/main/142-Labs/Lab 09 - Power Series and Taylor Series.ipynb
Views: 491
Kernel: SageMath 9.2

Lab 09 - Power Series and Taylor Series

Overview

There are two fundamental questions to ask about a power series n=0cn(xa)n.\displaystyle \sum_{n=0}^\infty c_n(x-a)^n.

  1. For what values of xx does the infinite sum converge?

  2. When the series converges, to what function does it converge? Notice that, in this case, the series is the Taylor series of the function.

We can answer the first question by finding the radius of convergence using the ratio test for absolute convergence and then checking the endpoints if needed.

The second question, is in general, much more difficult to answer. One useful technique is to apply common operation (substitution, multiplication, division, differntiation, integration, \dots) to a known power series, such as the Taylor series of a basic function. Also, SageMath can usually determine the function that a series converges to.

One important application of power series is to approximate a function using partial sums of its Taylor series, known as Taylor polynomials. The accuracy of the approximation depends on the size of the interval called for and the number of terms used in the partial sum. We will visualize this approximation using SageMath.

Sections 10.7 - 10.9 Be sure to know the following basic Taylor series.
1)  11x=n=0xn,  1<x<12)  ex=n=0xnn!,  <x<3)  sin(x)=n=0(1)nx2n+1(2n+1)!,  <x<4)  cos(x)=n=0(1)nx2n(2n)!,  <x<5)  ln(1+x)=n=0(1)nxn+1n+1,  1<x1\begin{array}{ll} 1) \ \ \dfrac{1}{1-x} = \displaystyle\sum_{n=0}^\infty x^n, \ \ -1 < x < 1 & \hspace{.5in} 2) \ \ e^x = \displaystyle\sum_{n=0}^\infty \dfrac{x^n}{n!}, \ \ -\infty < x < \infty \\ 3) \ \ \sin(x) = \displaystyle\sum_{n=0}^\infty \dfrac{(-1)^nx^{2n+1}}{(2n+1)!}, \ \ -\infty < x < \infty & \hspace{.5in} 4) \ \ \cos(x) = \displaystyle\sum_{n=0}^\infty \dfrac{(-1)^nx^{2n}}{(2n)!}, \ \ -\infty < x < \infty \\ 5) \ \ \ln(1 + x) = \displaystyle\sum_{n=0}^\infty \dfrac{(-1)^n x^{n+1}}{n+1}, \ \ -1 < x \leq 1 & \end{array}

Example 1

Consider the power series n=0xn+1(n+1)5n+1.\displaystyle \sum_{n=0}^\infty \dfrac{x^{n+1}}{(n+1)5^{n+1}}. We will

  1. Find the interval of convergence and radius of convergence of this series.

  2. Find the function which this series converges to.

  3. Plot approximations of the function using the first 10 partial sums of its Taylor series.

We will find the interval of convergence for the series using the ratio test for absolute convergence. We first define the terms ana_n in SageMath.

n = var('n') def a(n): return x^(n+1)/((n+1)*5^(n+1))

The first step in the ratio test for absolute convergence is to find all xx that make ρ=limnan+1an<1.\rho = \displaystyle \lim_{n\rightarrow \infty} \dfrac{|a_{n+1}|}{|a_n|} < 1. Let us find an expression for ρ\rho.

r = abs(a(n+1)/a(n)) rho = limit(r, n=infinity) show(rho)

Therefore, we need to find all xx such that x5<1\frac{|x|}{5} < 1. We can easily solve this inequality and get 5<x<5.-5 < x < 5. We also could have used SageMath.

solve(rho < 1, x)

Therefore, the radius of convergence is 5. We need to check the what happens at the endpoints x=5x=-5 and x=5x=5. We will create the sum in SageMath and evaluate it at these endpoints. In order to define the sum, we need to use the assume\textbf{assume} command to force xx to be in the interval of convergence.

forget() ## To forget any assumptions that may have already been made assume(x<5) assume(x>-5) S = sum(a(n),n,0,infinity) forget() ## It's good to forget assumptions once you are done with them so they don't affect your later calculations show(S)
S(-5)
S(5)

Therefore, we see that the series converges at x=5x = -5 but diverges at x=5x = 5. Thus, the interval of convergence is [5,5).[-5,5).

Remember that SageMath uses log\log for ln\ln. It follows that n=0xn+1(n+1)5n+1=ln(1x5)\displaystyle \sum_{n=0}^\infty \dfrac{x^{n+1}}{(n+1)5^{n+1}} = -\ln\left(1 - \dfrac{x}{5}\right) for x[5,5).x\in[-5,5). Note that we could have found this without using SageMath by using the Taylor series for ln(1+x)\ln(1 + x) given above and replacing xx with x5.-\frac{x}{5}.

Now that we have found the function which the power series converges to, we will use the interactive plotting function ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 13: \textbf{Plot_̲Taylor_Polynomi… located in the ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{uofsc_̲calculus_labs} package to plot approximations of the function by plotting its first 10 Taylor Polynomials.

from uofsc_calculus_labs import Plot_Taylor_Polynomials

Recall that if you get the error "No module named uofsc_calculus_labs", then you need to install it using the command below.

Note: \textbf{Note: } If you are using a lab computer or the Binder server, then you will not be able to use ParseError: KaTeX parse error: Unexpected end of input in a macro argument, expected '}' at end of input: \textbf{%pip}; however, ParseError: KaTeX parse error: Expected 'EOF', got '_' at position 14: \textbf{uofsc_̲calculus_labs} should already be installed.

%pip install uofsc_calculus_labs
from uofsc_calculus_labs import Plot_Taylor_Polynomials

To use the interactive plotting function, run the command below. Change the function in ff to the function that the power series converges to. Also, change the center and radius of convergence to the appropriate values for the series.

Plot_Taylor_Polynomials()

Example 2

For the following power series, do the following:

  1. Find the interval of convergence and radius of convergence of the series.

  2. Find the function which the series converges to.

  3. Use the interactive plotting tool to plot approximations of the function using the first 10 partial sums of its Taylor series.

a)  n=0x2nb)  n=0xn+1n!c)  n=0(1)nx2n(2n+1)!d)  n=0nxn1e)  n=0n(n1)xn2f)  n=0xn+1n+1g)  n=0(x1)nh)  n=0(xx2)nn!i)  n=0x2n+12n+1\begin{array}{lll} a) \ \ \displaystyle\sum_{n=0}^\infty x^{2n} & \hspace{.6in} b) \ \ \displaystyle\sum_{n=0}^\infty \dfrac{x^{n+1}}{n!} & \hspace{.6in} c) \ \ \displaystyle\sum_{n=0}^\infty \dfrac{(-1)^nx^{2n}}{(2n+1)!} \\ d) \ \ \displaystyle\sum_{n=0}^\infty nx^{n-1} & \hspace{.6in} e) \ \ \displaystyle\sum_{n=0}^\infty n(n-1)x^{n-2} & \hspace{.6in} f) \ \ \displaystyle\sum_{n=0}^\infty \dfrac{x^{n+1}}{n+1} \\ g) \ \ \displaystyle\sum_{n=0}^\infty (x-1)^n & \hspace{.6in} h) \ \ \displaystyle\sum_{n=0}^\infty \dfrac{(x - x^2)^n}{n!} & \hspace{.6in} i) \ \ \displaystyle\sum_{n=0}^\infty \dfrac{x^{2n+1}}{2n+1} \end{array}