1
00:00:00,060 --> 00:00:04,260
So as we have seen, expanding the exponential function works quite well.

2
00:00:04,890 --> 00:00:11,520
And the reason is that the exponential function is probably the most easy function to expand besides

3
00:00:11,520 --> 00:00:18,150
polynomials, because the here the derivative of every position is the same.

4
00:00:18,390 --> 00:00:24,180
So the first derivative, second derivative and in general, the derivative, it's always the exponential

5
00:00:24,180 --> 00:00:26,670
function at this particular position.

6
00:00:27,460 --> 00:00:32,610
It's not will continue with the second example, which is to sign function, and we will expand this

7
00:00:32,610 --> 00:00:33,360
at the position.

8
00:00:33,380 --> 00:00:35,130
X0 is equal to zero.

9
00:00:35,910 --> 00:00:40,860
And here the derivatives change, but they are quite similar.

10
00:00:40,860 --> 00:00:46,560
So in fact, we only have zeros, ones and minus ones in the derivatives.

11
00:00:47,310 --> 00:00:54,840
So this is because the actual value of sign of the same function is zero for an argument of zero.

12
00:00:55,410 --> 00:01:02,130
The first derivative is cosine of zero, which is one second derivative is minus zero minus sign of

13
00:01:02,130 --> 00:01:03,150
zero, which is zero.

14
00:01:03,480 --> 00:01:08,940
And then the third derivative is minus cosine of zero, which is minus one.

15
00:01:09,630 --> 00:01:14,730
And then starting from the fourth derivative, all of the derivatives will repeat.

16
00:01:14,820 --> 00:01:20,670
So then the fourth derivative will again be the function itself sine of X, and so sine of zero will

17
00:01:20,670 --> 00:01:21,570
be zero again.

18
00:01:22,200 --> 00:01:25,650
So you see the first, fifth, ninth and so on.

19
00:01:25,650 --> 00:01:27,840
The river two and zero will be one.

20
00:01:28,260 --> 00:01:32,610
And the third, seventh and the 11th and so on derivative will be minus one.

21
00:01:33,240 --> 00:01:40,380
So we can expand the sine function in this Taylor expansion that is given here where the sign of terms

22
00:01:40,380 --> 00:01:40,980
change.

23
00:01:41,400 --> 00:01:44,160
And we have only the odd terms here.

24
00:01:45,270 --> 00:01:53,430
And when we change our index where the index is not really meant to be describing the power of the polynomial.

25
00:01:53,700 --> 00:02:00,750
But when we change it to this two and plus one where and equals zero corresponds to one and equal to

26
00:02:00,900 --> 00:02:01,890
corresponds.

27
00:02:02,460 --> 00:02:02,760
All right.

28
00:02:02,790 --> 00:02:06,540
And a quick one corresponds to three and equal to corresponds to five.

29
00:02:06,870 --> 00:02:10,590
Then we can express it in this series here.

30
00:02:11,490 --> 00:02:18,130
So now we can go ahead and define this, and I don't want to type everything again.

31
00:02:18,130 --> 00:02:24,390
So I will copy the code from the exponential function and I will write sine Taylor.

32
00:02:25,560 --> 00:02:30,990
And one thing that we have to take care of is that when we want to calculate it analytically, where

33
00:02:30,990 --> 00:02:33,090
the derivatives are zero, one and minus one.

34
00:02:33,390 --> 00:02:34,890
This only works at the position.

35
00:02:34,910 --> 00:02:36,630
Zero is equal to zero.

36
00:02:37,770 --> 00:02:45,870
We will later on define a very general Taylor expansion function for Python, where we will rule out

37
00:02:45,870 --> 00:02:46,800
this problem here.

38
00:02:46,890 --> 00:02:51,840
But for now, we cannot consider X0 because zero is always zero.

39
00:02:52,170 --> 00:02:58,440
So I will delete these two lines and now we can go ahead and we basically just have to change what is

40
00:02:58,440 --> 00:02:59,410
written down here.

41
00:03:00,180 --> 00:03:04,320
And I will start with the first thing I thought to be elite this.

42
00:03:04,650 --> 00:03:13,590
And then we can write minus one to the power of and then we can multiply and have this power, this

43
00:03:14,400 --> 00:03:18,120
x to the power of two times and plus one.

44
00:03:18,630 --> 00:03:21,150
And then we just have to divide by nine factorial.

45
00:03:21,150 --> 00:03:29,190
So we write and p dot dot factorial and the material will be calculated off to and plus one.

46
00:03:30,750 --> 00:03:33,870
And then we can plot this.

47
00:03:33,900 --> 00:03:40,500
So once again, I take the code for plotting the Taylor expansion of the exponential function.

48
00:03:41,040 --> 00:03:43,080
But of course, I will change it a bit.

49
00:03:43,500 --> 00:03:46,320
So this time I will plot from minus 10 to 10.

50
00:03:46,330 --> 00:03:55,260
I have tested this before and also I will plot from minus two to two for the UI range.

51
00:03:55,890 --> 00:03:58,350
And then, of course, we have to change it.

52
00:03:58,380 --> 00:04:01,560
This one to and pitot sine.

53
00:04:01,890 --> 00:04:03,360
This will be our reference plot.

54
00:04:04,140 --> 00:04:07,360
And then for the actual plots, we just have to replace this one.

55
00:04:07,360 --> 00:04:11,700
We have to write sign Taylor sine Taylor, sine Taylor.

56
00:04:12,420 --> 00:04:18,360
And for the and Max, we will write explicitly what we want.

57
00:04:18,390 --> 00:04:20,519
So here we don't need to position anymore.

58
00:04:20,850 --> 00:04:27,810
So we will just have to define and max and I want to use three, six and nine to show you the difference.

59
00:04:28,950 --> 00:04:35,310
So we will always expand around to Position X. Zero is equal to zero, but we take a different number

60
00:04:35,310 --> 00:04:36,660
of terms into account.

61
00:04:37,800 --> 00:04:42,930
When you look at the plots, you will see that the blue function or basically first of all, you could

62
00:04:42,930 --> 00:04:50,300
see that all the functions reproduced assign function very well from PI over to minus 2+.

63
00:04:50,310 --> 00:04:55,350
So from here to here, then the red and the green function they even work from.

64
00:04:56,460 --> 00:04:59,490
Yeah, you could say maybe minus PI to PI.

65
00:04:59,860 --> 00:05:05,950
So a whole period of the function and then the green function even works from minus two Pi two plus

66
00:05:05,950 --> 00:05:06,490
two PI.

67
00:05:07,090 --> 00:05:10,450
So this is already when you take into account nine terms.

68
00:05:10,810 --> 00:05:19,270
So you can imagine if you go one step further or several steps further and you right here black for

69
00:05:19,270 --> 00:05:22,240
the color and you take into account, I don't know, 18 terms.

70
00:05:22,930 --> 00:05:26,650
Then you can see the sine function is a very well reproduced.

71
00:05:27,580 --> 00:05:29,740
So this works pretty, pretty well.

72
00:05:30,430 --> 00:05:37,150
And we can, of course, also check this numerically by calculating the accuracy of the term sine of

73
00:05:37,150 --> 00:05:38,080
ten point five.

74
00:05:38,110 --> 00:05:45,700
This is just some arbitrary number, which gives some, yeah, some real number, and we can now compare

75
00:05:45,700 --> 00:05:51,850
this to our sine Taylor expansion, its position ten point five.

76
00:05:52,210 --> 00:05:59,770
And if we now go very high with the order, for example, 50, then you see the error is 10 to the power

77
00:05:59,770 --> 00:06:01,000
of minus 13.

78
00:06:01,010 --> 00:06:03,160
So it's, yeah, basically zero.

79
00:06:04,270 --> 00:06:11,170
So once again, you see that this works quite well and that we can approximate even these more complicated

80
00:06:11,170 --> 00:06:12,850
functions like assign function.

