Visualizing Taylor series using Matplotlib (Python)

   Hi Guys, In this blog I will try to explain Taylor Series using Matplotlib. Matplotlib is a package used to plot various graphs related to particular data as well as graphs of mathematical function.

To do this, I will use Jupyter Notebook.

Step I

Below are the list of packages used for this task:

1) matplotlib

2) pyplot as plt ( It provides us a MATLAB like interface for plots and graphs)

3) numpy as np   ( Used for selecting range of numbers and some mathematical function )

4) math as mt    ( Used for mathematical functions )

( Here as function is used to denote original package name into a sort form for our convenience )






Step II

We will take example of e^x for this task. We will plot graph for e^x function, then one by one we will plot the graph for taylor series. And interestingly the taylor series graph will approach the main function graph as we increase the number of terms in taylor series.

Some key points to be noted :
        1) plt.plot() function is used for plotting the graph
        2) plt.legend() function is used for labelling the different plots in same graph

Let's do the plotting :










Lets see our output:










    

    

As you can see from the graph, by increasing our terms in taylor series, it goes near the actual value of e^x. After writing terms upto infinity we can get exact value of e^x.


Thank You!

Comments