So as we have seen, expanding the exponential function works quite well.
And the reason is that the exponential function is probably the most easy function to expand besides
polynomials, because the here the derivative of every position is the same.
So the first derivative, second derivative and in general, the derivative, it's always the exponential
function at this particular position.
It's not will continue with the second example, which is to sign function, and we will expand this
at the position.
X0 is equal to zero.
And here the derivatives change, but they are quite similar.
So in fact, we only have zeros, ones and minus ones in the derivatives.
So this is because the actual value of sign of the same function is zero for an argument of zero.
The first derivative is cosine of zero, which is one second derivative is minus zero minus sign of
zero, which is zero.
And then the third derivative is minus cosine of zero, which is minus one.
And then starting from the fourth derivative, all of the derivatives will repeat.
So then the fourth derivative will again be the function itself sine of X, and so sine of zero will
be zero again.
So you see the first, fifth, ninth and so on.
The river two and zero will be one.
And the third, seventh and the 11th and so on derivative will be minus one.
So we can expand the sine function in this Taylor expansion that is given here where the sign of terms
change.
And we have only the odd terms here.
And when we change our index where the index is not really meant to be describing the power of the polynomial.
But when we change it to this two and plus one where and equals zero corresponds to one and equal to
corresponds.
All right.
And a quick one corresponds to three and equal to corresponds to five.
Then we can express it in this series here.
So now we can go ahead and define this, and I don't want to type everything again.
So I will copy the code from the exponential function and I will write sine Taylor.
And one thing that we have to take care of is that when we want to calculate it analytically, where
the derivatives are zero, one and minus one.
This only works at the position.
Zero is equal to zero.
We will later on define a very general Taylor expansion function for Python, where we will rule out
this problem here.
But for now, we cannot consider X0 because zero is always zero.
So I will delete these two lines and now we can go ahead and we basically just have to change what is
written down here.
And I will start with the first thing I thought to be elite this.
And then we can write minus one to the power of and then we can multiply and have this power, this
x to the power of two times and plus one.
And then we just have to divide by nine factorial.
So we write and p dot dot factorial and the material will be calculated off to and plus one.
And then we can plot this.
So once again, I take the code for plotting the Taylor expansion of the exponential function.
But of course, I will change it a bit.
So this time I will plot from minus 10 to 10.
I have tested this before and also I will plot from minus two to two for the UI range.
And then, of course, we have to change it.
This one to and pitot sine.
This will be our reference plot.
And then for the actual plots, we just have to replace this one.
We have to write sign Taylor sine Taylor, sine Taylor.
And for the and Max, we will write explicitly what we want.
So here we don't need to position anymore.
So we will just have to define and max and I want to use three, six and nine to show you the difference.
So we will always expand around to Position X. Zero is equal to zero, but we take a different number
of terms into account.
When you look at the plots, you will see that the blue function or basically first of all, you could
see that all the functions reproduced assign function very well from PI over to minus 2+.
So from here to here, then the red and the green function they even work from.
Yeah, you could say maybe minus PI to PI.
So a whole period of the function and then the green function even works from minus two Pi two plus
two PI.
So this is already when you take into account nine terms.
So you can imagine if you go one step further or several steps further and you right here black for
the color and you take into account, I don't know, 18 terms.
Then you can see the sine function is a very well reproduced.
So this works pretty, pretty well.
And we can, of course, also check this numerically by calculating the accuracy of the term sine of
ten point five.
This is just some arbitrary number, which gives some, yeah, some real number, and we can now compare
this to our sine Taylor expansion, its position ten point five.
And if we now go very high with the order, for example, 50, then you see the error is 10 to the power
of minus 13.
So it's, yeah, basically zero.
So once again, you see that this works quite well and that we can approximate even these more complicated
functions like assign function.