1
00:00:00,690 --> 00:00:06,960
Welcome back to the course, but we have so far discussed how to calculate first derivatives of functions.

2
00:00:07,800 --> 00:00:11,220
And now we want to discuss how we can calculate higher derivatives.

3
00:00:11,770 --> 00:00:18,030
So for example, here is a second derivative and mathematically speaking, this is totally easy.

4
00:00:18,510 --> 00:00:23,970
You just take the function, calculate the first derivative and then from the first derivative, you

5
00:00:23,970 --> 00:00:27,510
calculate the second derivative in exactly the same way.

6
00:00:28,170 --> 00:00:34,950
So once again, you take the limit to zero of the first derivative and you introduce such a small value,

7
00:00:35,340 --> 00:00:36,870
which then goes to zero.

8
00:00:39,060 --> 00:00:44,700
So you see when we now use our definition for the first derivative and plug it in here.

9
00:00:44,970 --> 00:00:49,560
This gives us many possibilities for the definition of the second derivative.

10
00:00:50,520 --> 00:00:56,550
So, for example, we could use here the forward method here, the Beckworth method we could use here

11
00:00:56,550 --> 00:01:01,890
the central method to forward methods so we can combine all of these methods and we have to figure out

12
00:01:01,890 --> 00:01:03,690
which one is the best way to do it.

13
00:01:05,010 --> 00:01:09,990
So as an example, we could, for example, use double forwhat.

14
00:01:10,470 --> 00:01:17,520
So this means we start from this equation and we use for the f first derivative and this one also the

15
00:01:17,520 --> 00:01:18,390
forward method.

16
00:01:19,050 --> 00:01:26,820
So this means for this term, we will get the function and x plus two h minus the function of X plus

17
00:01:26,820 --> 00:01:30,720
one h divided by h divided by h.

18
00:01:31,170 --> 00:01:34,590
So this means we have this term here divided by h squared.

19
00:01:35,550 --> 00:01:42,240
And then for the other term we get function and x plus h minus function and x divided by h divided by

20
00:01:42,240 --> 00:01:42,630
h.

21
00:01:42,690 --> 00:01:45,060
So we get this divided by square.

22
00:01:46,200 --> 00:01:50,910
And so if we solve these brackets here, we get this expression with the three terms.

23
00:01:52,860 --> 00:01:56,700
If we to the double backwards, it's pretty similar.

24
00:01:57,000 --> 00:01:58,440
We get a similar results.

25
00:01:58,710 --> 00:02:05,520
We get here just different arguments where we'll use the previous point and the second nabor point in

26
00:02:05,520 --> 00:02:08,520
the previous direction or in the backward direction.

27
00:02:10,380 --> 00:02:14,610
What we can also do is, of course, we can combine forward and backward methods.

28
00:02:14,880 --> 00:02:16,890
So this means we start from here.

29
00:02:16,890 --> 00:02:20,010
But do you use the backward method for this one and for this one?

30
00:02:20,670 --> 00:02:31,770
So here we will get f off x plus h minus f of X, and here we will get f off x minus f of x minus h.

31
00:02:32,280 --> 00:02:35,100
And so if we solve then the brackets, we get this one.

32
00:02:36,000 --> 00:02:45,630
So we get f at the next point minus two times F at the current point, + f at x minus the previous point.

33
00:02:46,470 --> 00:02:51,630
And then we divide all cases by age square and take the limit h to zero.

34
00:02:53,130 --> 00:02:57,480
This is exactly the same result as we get for using the double central methods.

35
00:02:59,490 --> 00:03:07,680
Here we would just have then x plus two h minus two times F and X plus f x minus two h divided by four

36
00:03:07,680 --> 00:03:08,400
h square.

37
00:03:08,820 --> 00:03:15,780
But since h, uh, goes to zero, we can also substitute it with a new variable to Asia's equal to G.

38
00:03:16,110 --> 00:03:19,800
And then we have this expression and this is exactly the same as this one.

39
00:03:20,940 --> 00:03:25,470
So don't worry if this is too mathematical for you, it's not a big deal.

40
00:03:25,870 --> 00:03:33,060
The main message here is that in the end, we have once again a forward method, a backward method and

41
00:03:33,060 --> 00:03:34,320
a central point methods.

42
00:03:35,100 --> 00:03:41,660
And these ones we are going to implement now and we will like previously for the first derivative,

43
00:03:41,670 --> 00:03:42,720
we will compare them.

44
00:03:43,500 --> 00:03:48,540
And since it's so similar, let me copy the code from previously.

45
00:03:48,990 --> 00:03:49,770
So this one?

46
00:03:51,330 --> 00:03:57,660
And let me just paste it here at the bottom and updated for the second derivative.

47
00:03:59,280 --> 00:04:03,060
So we have here the analytical de-list, which we don't need anymore.

48
00:04:03,360 --> 00:04:08,250
And instead, we need the analytical D to list for the second derivative.

49
00:04:09,030 --> 00:04:10,980
And so here we need to think a bit.

50
00:04:11,040 --> 00:04:14,460
Maybe let's first do the last term because this is most easy.

51
00:04:14,960 --> 00:04:16,019
It's just this one.

52
00:04:17,640 --> 00:04:22,079
And then we calculate here the derivative, which is

53
00:04:24,360 --> 00:04:25,110
cosine.

54
00:04:25,950 --> 00:04:27,900
Then from here we get to terms.

55
00:04:27,900 --> 00:04:30,780
The first term will be cosine times one.

56
00:04:30,810 --> 00:04:41,160
So we get this term second time and the other term will be like this with a minus sign because a derivative

57
00:04:41,160 --> 00:04:42,690
of cosine is minus sine.

58
00:04:44,190 --> 00:04:47,880
So we update this two analytical D2 lists.

59
00:04:48,570 --> 00:04:51,570
And here we update the label to the second derivative.

60
00:04:52,100 --> 00:04:58,440
And now we must update these lists here to the to the to the two tier as well.

61
00:04:58,890 --> 00:04:59,960
And of course, now we must.

62
00:05:00,000 --> 00:05:05,220
Update the values themselves, so in all cases, we have here to square.

63
00:05:06,390 --> 00:05:17,520
And here we now also have an h square and here we have X list plus two times h minus two times f x list

64
00:05:17,520 --> 00:05:18,420
plus each.

65
00:05:19,500 --> 00:05:27,600
And then we have plus f x list.

66
00:05:30,030 --> 00:05:32,490
And the other terms are pretty similar.

67
00:05:32,490 --> 00:05:33,720
So I will just copy them.

68
00:05:34,410 --> 00:05:41,220
And here the difference is that we have had like this minus two times h.

69
00:05:41,820 --> 00:05:43,440
And here we have it like this.

70
00:05:48,500 --> 00:05:54,530
Yes, so I have not implemented the double forward, double backwards and the double central, which

71
00:05:54,530 --> 00:05:56,720
is equivalent to the forward and backward methods.

72
00:05:57,560 --> 00:06:05,150
And when I run this, we see first of all, it seems to be correct because all four curves are roughly

73
00:06:05,150 --> 00:06:05,780
the same.

74
00:06:05,930 --> 00:06:09,080
And we know that the analytical result is, of course, always correct.

75
00:06:11,300 --> 00:06:19,040
And you see also that there are some differences you can really see here yellow, red and also green.

76
00:06:19,910 --> 00:06:26,600
So once again, let us compare the differences and we do this, of course, in the same way as previously

77
00:06:26,600 --> 00:06:28,370
we right here Arrow.

78
00:06:29,240 --> 00:06:30,500
And we right here.

79
00:06:35,250 --> 00:06:41,190
That we calculate the difference between these two lists, and we always take the analytical list as

80
00:06:41,190 --> 00:06:42,090
a reference point.

81
00:06:43,140 --> 00:06:46,560
And then we also change the color of the plot.

82
00:06:46,740 --> 00:06:47,970
So here we use red.

83
00:06:48,810 --> 00:06:49,770
Here we use blue.

84
00:06:50,760 --> 00:06:51,990
And here we use green.

85
00:06:56,410 --> 00:07:02,560
So as previously, the red and blue curves double forward and the double back watch are not as good

86
00:07:02,560 --> 00:07:07,900
as the double central or combined forward and backward mechanism.

87
00:07:08,500 --> 00:07:14,170
And the reason is, of course, it's pretty similar to previously when we would do now the Taylor expansion,

88
00:07:14,170 --> 00:07:19,720
we would see that the double central methods would have pearls that cancel out.

89
00:07:19,720 --> 00:07:22,450
And so the accuracy would be much, much better.

90
00:07:24,130 --> 00:07:26,710
Now, this is not really surprising.

91
00:07:27,070 --> 00:07:33,250
And also, it's not surprising that we can now also take into account further nearest neighboring points

92
00:07:33,610 --> 00:07:35,530
to achieve a higher accuracy.

93
00:07:36,370 --> 00:07:40,480
And this time, the Richardson formula is given by this expression.

94
00:07:40,900 --> 00:07:44,770
So once again, we take the nearest and to second nearest neighboring points.

95
00:07:45,280 --> 00:07:53,140
And I will just use the code from previously to update to update our function.

96
00:07:53,620 --> 00:08:00,280
So I will use this one and also I will use the following cell.

97
00:08:00,550 --> 00:08:01,900
Let me copy this as well.

98
00:08:07,180 --> 00:08:13,030
Until this time, of course, we will now have to detour Richardson, and we must update now this equation,

99
00:08:13,510 --> 00:08:25,180
which will be minus F and X minus two h plus 16, that we have an additional term that cancels out previously,

100
00:08:25,180 --> 00:08:34,360
which is minus three times f of X than we have plus 16 and minus those one is OK is correct.

101
00:08:36,070 --> 00:08:39,970
OK, now we just change what we have written down here.

102
00:08:40,299 --> 00:08:46,570
D2, Richardson, Richardson, d to list and then we just update here everywhere.

103
00:08:46,930 --> 00:08:49,270
D two and here as well.

104
00:08:52,840 --> 00:09:04,210
And now I run both cells, and we see that apparently I made a mistake, which is OK, but let's see

105
00:09:04,210 --> 00:09:05,530
if we can find the mistake.

106
00:09:06,130 --> 00:09:13,900
So it seems as if the Richardson function gives a large arrow, but we know that this is not what's

107
00:09:13,900 --> 00:09:14,950
supposed to happen.

108
00:09:15,250 --> 00:09:17,560
And of course, here I forgot something here.

109
00:09:17,560 --> 00:09:19,630
It's one of a 12h square.

110
00:09:19,840 --> 00:09:22,330
So here we missed the square.

111
00:09:23,530 --> 00:09:25,150
And this time it looks much better.

112
00:09:25,540 --> 00:09:25,920
Yeah.

113
00:09:25,930 --> 00:09:33,160
This time we have an error for the double of central methods of approximately six times 10 to the minus

114
00:09:33,520 --> 00:09:36,430
three and four the Richardson method.

115
00:09:36,440 --> 00:09:40,450
We have an error of 10 to the minus five.

116
00:09:41,260 --> 00:09:46,750
So it is, I don't know, maybe, yeah, like 500 times better.

117
00:09:47,830 --> 00:09:53,080
So the logic behind this is really, really similar to the first derivatives.

118
00:09:53,590 --> 00:09:58,390
You can calculate the second derivatives pretty similarly.

119
00:09:58,390 --> 00:10:05,890
You just have to use the first derivative equations and plug them into each other so that you end up

120
00:10:05,890 --> 00:10:08,890
with some double forward, double backward or double the central methods.

121
00:10:09,520 --> 00:10:15,540
And then you will also find once again that some of these equations are better than others, and you

122
00:10:15,550 --> 00:10:19,750
could understand this analytically if you would write down the tether expansion.

123
00:10:20,140 --> 00:10:23,260
But yeah, that's a bit too much of a hassle here.

124
00:10:23,270 --> 00:10:27,220
We just believe these results and just analyze it numerically.

125
00:10:27,700 --> 00:10:33,400
And what we found is that the double central method works much, much better than the double forwhat

126
00:10:33,400 --> 00:10:40,090
and the double backward methods, and that there exist even better methods like the Richardson equation

127
00:10:40,090 --> 00:10:45,820
that is given here, which is based on taking into account also second nearest neighboring points.

128
00:10:46,840 --> 00:10:55,030
So this is all not really surprising because it is absolutely identical to the first derivative procedure

129
00:10:55,030 --> 00:10:57,580
that we have discussed in the previous lectures.

130
00:10:58,210 --> 00:11:03,970
Still is, of course, very important to keep in mind that this also works for the higher derivatives.

