""" Hello Peter, this is your test of the Taylor series for sin(x) """ # import some tools to make life easier import numpy as np # np.pi means 3.1415.., np.sin(x) is Sinus import matplotlib.pyplot as plt # use plt to plot something on the screen print("Here is Taylor.py") # Just a test for an angle of 10 degree x_degree = 10.0 x = x_degree * np.pi / 180. # convert to radian print("x_degree =", x_degree ) print("x =", x ) # x radian print("x-x**3/6 =", x - x**3 / 6. ) # first terms of Taylor expansion of sin(x) print("sin(x) =", np.sin(x) ) # full precision sinus # plot sinus and the first approximations of a Taylor expansion # a list of angles between 0 and 120 degree in steps of 5 degree xl_degree = np.arange( 0.0, 120.0, 5.0 ) # creates a list of numbers xl = xl_degree * np.pi / 180. # converts to radian plt.clf() # remove previous plot (if existing) print("Sinus(x) is blue.") plt.plot(xl, np.sin(xl) , 'b-') # b =blue, - = simple line plt.plot(xl, xl, 'r:') # r = red : = dotted plt.plot(xl, xl - xl**3/6., 'g-.') # c = cyan -. = dash/dott plt.plot(xl, xl - xl**3/6., 'g*') # g = green, * = stars plt.xlabel("angle [radian]") plt.ylabel("Taylor of sin(x)") plt.show() # display result of plt.plot commands