1
00:00:05,126 --> 00:00:06,720
PROFESSOR: Hi everyone.

2
00:00:06,720 --> 00:00:07,850
Welcome back.

3
00:00:07,850 --> 00:00:09,930
So today, I'd like
to tackle a problem

4
00:00:09,930 --> 00:00:15,087
in numerical integration of ODEs
specifically on Euler's method.

5
00:00:15,087 --> 00:00:17,295
And the problem we're
interested in considering today

6
00:00:17,295 --> 00:00:21,670
is the ODE y prime equals
y squared minus xy.

7
00:00:21,670 --> 00:00:24,750
And we're interested in
integrating the solution

8
00:00:24,750 --> 00:00:27,820
that starts at y of zero
is equal to negative 1

9
00:00:27,820 --> 00:00:30,400
using a step size of 0.5.

10
00:00:30,400 --> 00:00:32,880
And we want to
integrate it to y of 1.

11
00:00:32,880 --> 00:00:34,630
And then for the
second part, we're

12
00:00:34,630 --> 00:00:37,710
interested in if our
first step of integration

13
00:00:37,710 --> 00:00:39,910
either overestimates
or underestimates

14
00:00:39,910 --> 00:00:41,387
the exact solution.

15
00:00:41,387 --> 00:00:43,970
So I'll let you think about this
and work it out for yourself,

16
00:00:43,970 --> 00:00:45,261
and I'll come back in a moment.

17
00:00:57,990 --> 00:00:58,990
Hi everyone.

18
00:00:58,990 --> 00:01:00,400
Welcome back.

19
00:01:00,400 --> 00:01:03,470
So as I mentioned before,
this is a problem in numerics.

20
00:01:03,470 --> 00:01:05,616
And specifically, whenever
you're given an ODE,

21
00:01:05,616 --> 00:01:06,990
you can almost
always numerically

22
00:01:06,990 --> 00:01:08,830
integrate it on a computer.

23
00:01:08,830 --> 00:01:11,020
And this is quite possibly
the simplest algorithm

24
00:01:11,020 --> 00:01:13,590
for numerical integration.

25
00:01:13,590 --> 00:01:15,380
So specifically,
what we do is we

26
00:01:15,380 --> 00:01:18,000
take the left-hand side,
the derivative, y prime,

27
00:01:18,000 --> 00:01:21,590
and we approximate it using a
very simple finite difference

28
00:01:21,590 --> 00:01:22,090
formula.

29
00:01:26,450 --> 00:01:29,940
So if I take y prime and
approximate it as y of n

30
00:01:29,940 --> 00:01:39,540
plus 1 minus y of n divided by
h, where h is the step size,

31
00:01:39,540 --> 00:01:44,430
then I can approximate
the continuous ODE

32
00:01:44,430 --> 00:01:46,600
using this simple formula.

33
00:01:46,600 --> 00:01:50,250
So here h as I mentioned
is the step size.

34
00:01:54,150 --> 00:02:00,080
f, in this case, is the
right-hand side of the ODE.

35
00:02:04,890 --> 00:02:08,490
And we see that y of n plus
1 minus y of n divided by h

36
00:02:08,490 --> 00:02:09,880
is an approximation to y prime.

37
00:02:13,730 --> 00:02:15,430
In addition, we
can also write down

38
00:02:15,430 --> 00:02:20,386
x of n plus 1 is just
equal to x of n plus h.

39
00:02:23,570 --> 00:02:25,170
And I'm using
subscripts n here just

40
00:02:25,170 --> 00:02:28,670
to denote the step
of the algorithm.

41
00:02:28,670 --> 00:02:31,350
So for part A, we're
asked to integrate

42
00:02:31,350 --> 00:02:34,450
the solution-- it starts at y
of zero is equal to negative 1--

43
00:02:34,450 --> 00:02:36,550
to y of 1.

44
00:02:36,550 --> 00:02:44,890
So what this means for part A
is we want x of zero to be zero,

45
00:02:44,890 --> 00:02:47,790
and we want y of zero
to be negative 1.

46
00:02:52,890 --> 00:02:55,627
Now to further integrate this
equation, the quickest way

47
00:02:55,627 --> 00:02:57,710
to do it, especially if
you're in a test scenario,

48
00:02:57,710 --> 00:02:58,690
is to build a table.

49
00:03:01,410 --> 00:03:04,040
So a nice table to
build is one that

50
00:03:04,040 --> 00:03:12,240
has a column n, x of n, y of n.

51
00:03:12,240 --> 00:03:13,550
I'm going to write f of n.

52
00:03:16,170 --> 00:03:21,810
f of n is to denote f
evaluated at x of n and y of n.

53
00:03:24,650 --> 00:03:30,050
And then, it's also useful
to write down h times f of n

54
00:03:30,050 --> 00:03:33,540
because the quantity
h times f of n

55
00:03:33,540 --> 00:03:35,510
comes up in the
addition of y of n

56
00:03:35,510 --> 00:03:38,756
plus 1 is equal to y of
n plus h times f of n.

57
00:03:43,420 --> 00:03:45,712
And in the problem
under consideration,

58
00:03:45,712 --> 00:03:47,670
I'm just going to fill
in the first two columns

59
00:03:47,670 --> 00:03:48,890
because they're the easiest.

60
00:03:48,890 --> 00:03:52,420
We have n is equal
to 0, 1 and 2.

61
00:03:52,420 --> 00:03:54,540
X of n is starting off at zero.

62
00:03:54,540 --> 00:03:57,110
So x of zero is zero.

63
00:03:57,110 --> 00:04:01,370
x of 1 is going to be 0.5.

64
00:04:01,370 --> 00:04:06,160
And then, x of 2 is equal to 1.

65
00:04:06,160 --> 00:04:08,040
In addition, we're also
told that y of zero

66
00:04:08,040 --> 00:04:11,900
is equal to negative 1.

67
00:04:11,900 --> 00:04:19,380
And now for f of n, I'll
just use the side here,

68
00:04:19,380 --> 00:04:23,240
what's f of zero going to be?

69
00:04:23,240 --> 00:04:29,160
Well, it's going to be y of
zero minus x of zero y of zero.

70
00:04:32,370 --> 00:04:36,760
So this gives us 1 and 0.

71
00:04:36,760 --> 00:04:43,090
So we can fill in a 0.1 here,
which means that h times f of 1

72
00:04:43,090 --> 00:04:46,950
is going to be 0.5.

73
00:04:46,950 --> 00:04:52,540
And now with h of f of
n, we can fill in y of 1.

74
00:04:52,540 --> 00:04:57,690
So y of 1 is just going
to be y of zero plus 0.5.

75
00:04:57,690 --> 00:04:59,820
And y of zero is negative 1.

76
00:04:59,820 --> 00:05:06,250
So this is going
to be negative 0.5.

77
00:05:06,250 --> 00:05:09,810
Now, we need to fill in f of 1.

78
00:05:09,810 --> 00:05:16,450
So this is going to be y of 1
squared minus x of 1 y of 1.

79
00:05:16,450 --> 00:05:20,180
Now y of 1 squared, this
is negative 0.5 squared.

80
00:05:23,330 --> 00:05:26,860
x of 1 is 0.5.

81
00:05:26,860 --> 00:05:31,840
And y of 1 is,
again, negative 0.5.

82
00:05:31,840 --> 00:05:36,190
So this gives us one
quarter plus one quarter,

83
00:05:36,190 --> 00:05:41,310
which together is just 0.5.

84
00:05:41,310 --> 00:05:44,310
So we have 0.5 in
this square now.

85
00:05:44,310 --> 00:05:53,430
And then h times 0.5 is 0.5
squared, which is just 0.25.

86
00:05:53,430 --> 00:05:58,870
Now y of 2 is just going to
be y of 1 plus h times f of 1.

87
00:05:58,870 --> 00:06:03,360
So we know h of f of
1 is 0.25, and y of 1

88
00:06:03,360 --> 00:06:06,100
is just negative 0.5.

89
00:06:06,100 --> 00:06:12,380
So this is going to
be negative 0.25.

90
00:06:12,380 --> 00:06:17,160
And we note that this is the
answer we're looking for.

91
00:06:17,160 --> 00:06:24,260
So just to conclude, our
approximation y of 2,

92
00:06:24,260 --> 00:06:29,840
which is approximately
y evaluated at 1,

93
00:06:29,840 --> 00:06:36,990
is going to be negative 0.25.

94
00:06:36,990 --> 00:06:43,630
So for part B, we're asked does
our approximation negative 0.25

95
00:06:43,630 --> 00:06:46,870
overestimate or underestimate
the actual exact solution

96
00:06:46,870 --> 00:06:49,710
of the ODE?

97
00:06:49,710 --> 00:06:51,350
Now, in general,
what you want to do

98
00:06:51,350 --> 00:06:53,140
is you want to take
the second derivative.

99
00:06:53,140 --> 00:06:54,390
However, for this
problem, we're only

100
00:06:54,390 --> 00:06:55,770
going to consider
the first step.

101
00:06:55,770 --> 00:06:58,970
So our first step, does it
overestimate or underestimate

102
00:06:58,970 --> 00:07:00,750
the exact solution?

103
00:07:00,750 --> 00:07:02,420
And to do this,
what we want to do

104
00:07:02,420 --> 00:07:04,570
is we want to take a
look at the concavity.

105
00:07:04,570 --> 00:07:07,230
So we want to look
at y double prime.

106
00:07:07,230 --> 00:07:13,260
So y double prime is going
to be d by dx of y prime.

107
00:07:13,260 --> 00:07:18,240
And we know from the ODE y
prime is y squared minus xy.

108
00:07:18,240 --> 00:07:23,630
So I can work this
out to be 2y y prime,

109
00:07:23,630 --> 00:07:32,010
just using the chain rule,
minus y minus x y prime.

110
00:07:32,010 --> 00:07:35,550
And at the first step, we're
interested in evaluating

111
00:07:35,550 --> 00:07:40,130
this quantity at the
point x equals zero,

112
00:07:40,130 --> 00:07:41,660
y is equal to negative 1.

113
00:07:41,660 --> 00:07:42,810
So this is the first step.

114
00:07:45,410 --> 00:07:50,470
So at x is equal to zero,
y is equal to negative 1,

115
00:07:50,470 --> 00:07:56,500
this simplifies to
minus 2y prime plus 1.

116
00:07:56,500 --> 00:07:59,580
This term right here drops off.

117
00:07:59,580 --> 00:08:03,910
And y prime specifically is
going to be y squared minus xy.

118
00:08:03,910 --> 00:08:12,370
So we get 2-- y squared is going
to be 1-- minus zero plus 1.

119
00:08:12,370 --> 00:08:15,704
So together, this is
going to give us minus 1.

120
00:08:15,704 --> 00:08:17,370
And we note that this
is less than zero.

121
00:08:21,490 --> 00:08:23,500
So we've just shown
that the concavity

122
00:08:23,500 --> 00:08:27,120
at our starting point, x equals
zero, y is equal to negative 1

123
00:08:27,120 --> 00:08:29,880
is less than zero.

124
00:08:29,880 --> 00:08:32,780
So what this means is that our
initial approximation is going

125
00:08:32,780 --> 00:08:35,257
to overestimate the solution.

126
00:08:35,257 --> 00:08:37,340
We can see that it's going
to overestimate it just

127
00:08:37,340 --> 00:08:38,089
by a quick sketch.

128
00:08:42,909 --> 00:08:45,650
For example, if I
were to plot y and x,

129
00:08:45,650 --> 00:08:49,500
we're starting off at this
point, x is equal to zero,

130
00:08:49,500 --> 00:08:51,330
y is equal to negative 1.

131
00:08:51,330 --> 00:08:56,360
So this is y(0) is
equal to negative 1.

132
00:08:56,360 --> 00:08:59,730
We know the exact
solution's increasing,

133
00:08:59,730 --> 00:09:03,470
and it's concave down
because the second derivative

134
00:09:03,470 --> 00:09:05,170
is negative 1.

135
00:09:05,170 --> 00:09:07,390
And by Euler's formula,
what we're doing is

136
00:09:07,390 --> 00:09:10,910
we're approximating the
solution using a tangent line

137
00:09:10,910 --> 00:09:11,790
at this point.

138
00:09:11,790 --> 00:09:14,340
So we can see that our
approximate solution

139
00:09:14,340 --> 00:09:18,200
when we take one step
to go from here to here,

140
00:09:18,200 --> 00:09:25,380
so this is x of zero, this is x
of 1, our solution which is now

141
00:09:25,380 --> 00:09:31,320
going to be y of 1 here is
going to overestimate the curve.

142
00:09:31,320 --> 00:09:34,260
And the reason it overestimates
it, I'll just reiterate again,

143
00:09:34,260 --> 00:09:37,930
is because our solution
is concave down.

144
00:09:37,930 --> 00:09:40,090
So this concludes the problem.

145
00:09:40,090 --> 00:09:43,640
And just to reiterate, when
dealing with Euler's method,

146
00:09:43,640 --> 00:09:46,160
the best thing to do is just
to build a table like this.

147
00:09:46,160 --> 00:09:49,530
And you can quickly work it out.

148
00:09:49,530 --> 00:09:51,520
Secondly, if you're
asked questions

149
00:09:51,520 --> 00:09:56,380
on if your numerical solution
overestimates or underestimates

150
00:09:56,380 --> 00:09:58,490
the exact solution,
typically what you want to do

151
00:09:58,490 --> 00:10:00,880
is you want to look
at the concavity.

152
00:10:00,880 --> 00:10:02,400
And then, you can
always just sketch

153
00:10:02,400 --> 00:10:04,780
a quick diagram on
the back of a notepad

154
00:10:04,780 --> 00:10:10,090
to see if the solution
overestimates or underestimates

155
00:10:10,090 --> 00:10:12,570
the exact solution.

156
00:10:12,570 --> 00:10:13,860
So I'd like to conclude here.

157
00:10:13,860 --> 00:10:15,670
And I'll see you next time.