1
00:00:09,510 --> 00:00:15,540
Okay, so today what we are going to do is;
we are going to look at approximating derivatives
2
00:00:15,540 --> 00:00:21,650
right, so far we looked at approximating functions,
right and we have seen there are lots of ways
3
00:00:21,650 --> 00:00:27,590
by which we can approximate functions. All
I have done by way of either box functions,
4
00:00:27,590 --> 00:00:34,180
hard functions, hat functions right, all of
cubics, quadratics cubic spline, quadratics
5
00:00:34,180 --> 00:00:36,740
and so on, it is just one class.
6
00:00:36,740 --> 00:00:41,260
There are many many ways by which you can
write approximate functions and represent
7
00:00:41,260 --> 00:00:47,150
them on the computer which is the most important
part that we are interested. Now, we saw in
8
00:00:47,150 --> 00:00:56,140
the last class that if you had a function
f of x and you wanted to find out what was
9
00:00:56,140 --> 00:01:05,000
its value at f of x + delta x. Let, we could
use Taylor series, right we could use Taylor
10
00:01:05,000 --> 00:01:10,890
series to write f of x + delta x in terms
of f of x, okay.
11
00:01:10,890 --> 00:01:16,180
So, for the sake of this discussion like I
did earlier, I will say h is approximately
12
00:01:16,180 --> 00:01:21,670
xi + 1 – xi, I know I have introduced delta
x because that is what you are used to seeing
13
00:01:21,670 --> 00:01:29,541
in your Taylor series formulas and so on,
right so I will write this as f of x + h is
14
00:01:29,541 --> 00:01:44,110
f of x + h times the derivative f prime of
x + h squared/ 2 factorial/ 2; second derivative
15
00:01:44,110 --> 00:01:57,150
of x and so on, 3 factorial, third derivative,
is that fine.
16
00:01:57,150 --> 00:02:06,850
So, I am just writing a Taylor series expansion
of f at x + h expanded about the point x,
17
00:02:06,850 --> 00:02:13,420
right that is usually; that is usually what
we call and it is possible for us one thing
18
00:02:13,420 --> 00:02:22,530
that we saw is it was possible for us to approximate
f at x + h in terms of these terms, the more
19
00:02:22,530 --> 00:02:26,180
information that you have, the more terms
that you can add. So, if you know the first
20
00:02:26,180 --> 00:02:32,609
derivative, you can get a representation whose
error is of the order of h squared and so
21
00:02:32,609 --> 00:02:33,609
on, right.
22
00:02:33,609 --> 00:02:38,200
The other possibility that we saw was that
we can actually use this to extract are the
23
00:02:38,200 --> 00:02:47,249
first derivative that is f prime of x can
be written as solving for f prime; f of x
24
00:02:47,249 --> 00:02:58,939
+ h - f of x/ h, then we have to take all
of these infinite number of terms to the other
25
00:02:58,939 --> 00:03:10,650
side and what will that give us? + excuse
me; -h/2 f double prime of x – h squared/
26
00:03:10,650 --> 00:03:22,669
3 factorial which is 6; the third derivative
of x and so on, okay.
27
00:03:22,669 --> 00:03:25,790
If you go back, if you think about one of
the definitions at least that you have seen
28
00:03:25,790 --> 00:03:32,209
of the; of getting the derivative of actually
calculating the derivative, right from first
29
00:03:32,209 --> 00:03:39,059
principles using limits, you would have seen
that f of x + h - f of x/ h, right limit h
30
00:03:39,059 --> 00:03:43,760
going to 0, it would be the definition of
the derivative and all of these terms will
31
00:03:43,760 --> 00:03:48,860
go to 0 and you will get the derivative, so
that is an infinite process, right.
32
00:03:48,860 --> 00:03:53,049
It is a limiting process, it is an infinite
process, we do not go through the infinite
33
00:03:53,049 --> 00:03:58,450
process, so we stay with a finite process
and therefore this is called the finite difference,
34
00:03:58,450 --> 00:04:06,579
okay, so we have a finite difference approximation
for the first derivative, I will truncate
35
00:04:06,579 --> 00:04:11,889
the series at that point; I will truncate
that series at that point. This error that
36
00:04:11,889 --> 00:04:27,140
you see here all the terms that I have truncated
called the truncation error.
37
00:04:27,140 --> 00:04:34,810
And the order of the truncation error is indicated
typically by the leading term, which is –h/
38
00:04:34,810 --> 00:04:48,670
2, the second derivative x, is that fine,
okay. So, the representation that we have
39
00:04:48,670 --> 00:04:57,090
for the derivative f prime of x, right is
f of x + h - f of x/h, if I am going to truncate
40
00:04:57,090 --> 00:05:01,840
it, then I have to replace this, it is really
more of an approximation rather than right;
41
00:05:01,840 --> 00:05:04,790
rather than being exact.
42
00:05:04,790 --> 00:05:13,400
So, you could call it f prime, you could;
we can indicate an H up there, prime of x,
43
00:05:13,400 --> 00:05:21,340
the h indicating that, right equals and as
I told you earlier, I will use this h to indicate
44
00:05:21,340 --> 00:05:25,420
that it is an approximation and after a point
maybe I will drop it where it is just clarity
45
00:05:25,420 --> 00:05:35,630
of that, I am actually talking about an approximation.
So, this is f of x + h - f of x/ h and the
46
00:05:35,630 --> 00:05:43,580
truncation error is –h/ 2, second derivative
of x.
47
00:05:43,580 --> 00:05:49,150
What does the nature of the truncation error?
In the limit h goes to 0, as h gets smaller
48
00:05:49,150 --> 00:05:55,930
and smaller, the truncation error is going
to go to 0 in a linear fashion; in a linear
49
00:05:55,930 --> 00:06:04,240
fashion okay, so the convergence is basically
first order convergence okay. For what polynomial;
50
00:06:04,240 --> 00:06:13,420
what degree polynomial is the truncation error
0? For a function that is linear, right for
51
00:06:13,420 --> 00:06:16,100
a function that is linear; for a function
that is linear.
52
00:06:16,100 --> 00:06:22,050
So, this sounds like the hat function, it
sounds like the hat function, remember what
53
00:06:22,050 --> 00:06:32,960
was the derivative of the hat function on
the interval xi - 1 or xi +1, so that was
54
00:06:32,960 --> 00:06:42,110
fi - fi – 1/ h, the same thing, okay. So,
we are essentially representing in a sense,
55
00:06:42,110 --> 00:06:45,540
we are representing the function when we do
this; when we go through this process we are
56
00:06:45,540 --> 00:06:50,210
representing the function using hat functions;
linear interpolants, okay.
57
00:06:50,210 --> 00:06:53,810
So and of course we will ask ourselves the
question, it can be do better than this and
58
00:06:53,810 --> 00:06:56,800
we can obviously do better than this because
we know that we can represent the function
59
00:06:56,800 --> 00:07:04,170
using quadratics, cubics and so on because
this function; because this approximation
60
00:07:04,170 --> 00:07:11,590
involves x + h and x and the derivative is
at x, right, we are using a point that is
61
00:07:11,590 --> 00:07:14,180
ahead; we are using a point that is ahead.
62
00:07:14,180 --> 00:07:26,270
So, I will again; so this is xi, this is xi
+ 1, right, so if I call this point, the function
63
00:07:26,270 --> 00:07:32,890
value here is fi, so I am saying that f prime,
I have already dropped the h to indicate,
64
00:07:32,890 --> 00:07:44,680
so I know it is f prime at the point i is
fi + 1 – fi/ h, since I am using a point
65
00:07:44,680 --> 00:07:57,810
that is ahead, this is called a forward difference,
this difference is called a forward difference;
66
00:07:57,810 --> 00:08:10,780
a forward difference, right. So, it is a forward
difference approximation, is that fine.
67
00:08:10,780 --> 00:08:14,141
So, if you can have a forward difference,
the natural question that you have is; can
68
00:08:14,141 --> 00:08:20,190
we have a backward difference? So, in order
to do that just like we did earlier, you say
69
00:08:20,190 --> 00:08:30,340
f of x = h is f of x, we just follow that
process, same process + h times f prime of
70
00:08:30,340 --> 00:08:43,890
x + h squared/ 2 factorial, second derivative
of x + cube 3 factorial; I am sorry, I am
71
00:08:43,890 --> 00:08:52,260
making a mistake here, I have to pay attention,
thank you very much; h cube f triple prime
72
00:08:52,260 --> 00:08:55,000
of x and so on.
73
00:08:55,000 --> 00:09:05,890
The sign change is important, okay, so in
therefore solving f prime, I just write it
74
00:09:05,890 --> 00:09:21,120
in the same notation; f prime at i is f at
i - f at i -1/ h
75
00:09:21,120 --> 00:09:38,520
and what is the truncation error? h/2 times
f double prime at i, this is –h/2, this
76
00:09:38,520 --> 00:09:53,580
is +h/ 2, is that fine, -h/2 and +h/2, the
signs are opposite, this is called a backward
77
00:09:53,580 --> 00:10:02,350
difference; backward difference, so that is
a backward difference approximation, is that
78
00:10:02,350 --> 00:10:03,350
okay.
79
00:10:03,350 --> 00:10:09,950
Okay, so we have a forward difference approximation,
we have a backward difference approximation,
80
00:10:09,950 --> 00:10:19,690
look at this so at the same; across the same
interval; across the same interval, I have
81
00:10:19,690 --> 00:10:28,630
these two across; I am not go there just a
second; so, I have i, i – 1, i + 1, so I
82
00:10:28,630 --> 00:10:38,430
have 1 representation for f prime i, which
is a forward difference, 1 approximation for
83
00:10:38,430 --> 00:10:47,410
the f prime, which is forward difference,
right at the point i; at the point i which
84
00:10:47,410 --> 00:10:50,500
equals fi + 1 – fi/ h.
85
00:10:50,500 --> 00:11:01,790
I am just rewriting that –h/2 f double prime
of x, then I have another approximation backward,
86
00:11:01,790 --> 00:11:17,830
I will just write back at i which is fi - fi
– 1/ h and the error here; truncation error
87
00:11:17,830 --> 00:11:30,010
here is; okay, is it possible for me to get
a better or better approximation if I give
88
00:11:30,010 --> 00:11:37,360
you these two to get a better approximation?
It looks like if I add this estimate and that
89
00:11:37,360 --> 00:11:41,100
estimate, this error will just cancel, you
understand.
90
00:11:41,100 --> 00:11:44,980
It looks like if I add this, so if I take
the average of these 2, so this is just by
91
00:11:44,980 --> 00:11:53,230
way of suggestion just way of from observation;
just from observation, f prime some approx
92
00:11:53,230 --> 00:12:09,300
i is; what is the average of these two? fi
+ 1, the - fi and + fi will cancel, - fi - 1
93
00:12:09,300 --> 00:12:14,130
/ 2h, this goes away, so I will have to go
back and calculate; recalculate my truncation
94
00:12:14,130 --> 00:12:19,649
error, so what would be my truncation error?
95
00:12:19,649 --> 00:12:31,190
What does my truncation error going to be
like, I have - h cubed/ 3 factorial which
96
00:12:31,190 --> 00:13:02,100
is + h cube by; truncation error is 2h squared/
3 factorial, it was has a; you can just do
97
00:13:02,100 --> 00:13:17,540
it, there is a -h squared by; there is a -h
squared/ 6 here, okay and what we going to
98
00:13:17,540 --> 00:13:28,880
get here? You have a +h squared/ 6, anyway
what we will do is; we will do; we will do
99
00:13:28,880 --> 00:13:33,190
this in the legal way, let me not so you can
try going through this process.
100
00:13:33,190 --> 00:13:38,880
You will see that will actually go through
this legal straightforward fashion instead
101
00:13:38,880 --> 00:13:43,510
of this intuitive, so here all I am saying
is if I look at this; this gives me a clue,
102
00:13:43,510 --> 00:13:47,850
I have a forward difference approximation,
I have a backward difference approximation
103
00:13:47,850 --> 00:13:53,500
in this fashion and it turns out that these
terms cancel, okay. So, when I say let us
104
00:13:53,500 --> 00:13:56,200
go about this legal way, what I am saying
is if you want to find the truncation error,
105
00:13:56,200 --> 00:13:57,270
there is only one way to do it.
106
00:13:57,270 --> 00:14:00,459
You have to get the series and actually do
the truncation error, so we have to get it
107
00:14:00,459 --> 00:14:07,240
from Taylor series okay. So, let us get back
to the first one, we get it from Taylor series,
108
00:14:07,240 --> 00:14:16,420
so it involves the points x + h and x – h,
so I will rewrite my Taylor series for x – h,
109
00:14:16,420 --> 00:14:33,970
f of x - h is f of x - h times f prime of
x + h squared/ 2 factorial f double prime
110
00:14:33,970 --> 00:14:47,000
of x - h cube/ 3 factorial f triple prime
of x and so on, is that okay.
111
00:14:47,000 --> 00:14:53,860
So, what I am going to do now, I want to solve,
so this is how you would do it, right so please
112
00:14:53,860 --> 00:14:58,340
do not go around taking averages and all that
was just for; that was just a question to
113
00:14:58,340 --> 00:15:02,720
lead us intuitively to this part, so this
is how you do it. What do I want from these
114
00:15:02,720 --> 00:15:08,040
two equations? I want to get f prime of x
that is my objective. I want to solve for
115
00:15:08,040 --> 00:15:12,830
f prime of x, so which means that from the
first equation, if I subtract the second equation,
116
00:15:12,830 --> 00:15:33,340
I will get 2 f prime
of x is f of x + h - f of x – h/; well,
117
00:15:33,340 --> 00:15:36,830
so I will remove the 2h.
118
00:15:36,830 --> 00:15:46,800
So, I am dividing through by 2h, what happens
to this term? It cancels, there are 2 of these
119
00:15:46,800 --> 00:15:54,460
but I divide it by 2 okay and therefore, I
get and we have to make sure that the sign
120
00:15:54,460 --> 00:16:08,070
is right, we have a - h squared/ 6 f third
derivative of x and so on and other terms
121
00:16:08,070 --> 00:16:24,610
that would be the truncation error, okay.
So, in this particular case as h goes to 0,
122
00:16:24,610 --> 00:16:31,700
we converge quadratically okay, the error
goes to 0 quadratically, h squared.
123
00:16:31,700 --> 00:16:39,510
And what about the polynomial that we are
using, that is also quadratic; that is also
124
00:16:39,510 --> 00:16:44,242
quadratic okay, that is also by chance it
happens, then that it is also quadratic, it
125
00:16:44,242 --> 00:16:47,640
is also a second degree polynomial, we can
represent a second degree polynomial; we use
126
00:16:47,640 --> 00:16:52,330
a second degree polynomial for f, this term
will be 0 and f prime we will get the right
127
00:16:52,330 --> 00:16:57,820
answer, is that fine, okay. So, essentially
we are using parabolics to represent the f
128
00:16:57,820 --> 00:16:59,820
in this case, right.
129
00:16:59,820 --> 00:17:06,430
Though we are not actually constructed the
quadratic, all we have is those points, if
130
00:17:06,430 --> 00:17:15,449
you go back and try to find the coefficients,
right for the quadratics and cubics, if you
131
00:17:15,449 --> 00:17:21,140
go back right, we did; you have done as repeat
we have done hat functions, quadratics cubics
132
00:17:21,140 --> 00:17:26,150
I have not used quadratics and cubics to represent
functions, right I would suggest that you
133
00:17:26,150 --> 00:17:31,590
try it. If you go back and try to do it, when
you look at you will get a system of equations
134
00:17:31,590 --> 00:17:32,590
for the coefficients.
135
00:17:32,590 --> 00:17:36,400
And when you look at the system of equations
for the coefficients and solve for the coefficient,
136
00:17:36,400 --> 00:17:40,700
we will be surprised that you should not be
surprised that you will get terms like this,
137
00:17:40,700 --> 00:17:44,540
just try it out, right. There is the reason
why I asked you to do it, if you done it this
138
00:17:44,540 --> 00:17:48,480
should look familiar, right, you should; there
is suppose, to be an aha moment for you saying
139
00:17:48,480 --> 00:17:53,090
that ah, I have seen this right, when I did
the quadratic, I got exactly the same expression,
140
00:17:53,090 --> 00:17:54,090
okay.
141
00:17:54,090 --> 00:18:02,210
So, there is a connection between this and
that the quadratic; coefficients of the quadratic,
142
00:18:02,210 --> 00:18:11,730
okay, well so this is what we have, let me
make an observation here and then we will
143
00:18:11,730 --> 00:18:24,690
see what is it that I am going to choose an
interval to see what it is that we have. This
144
00:18:24,690 --> 00:18:38,510
is i, this is i + 1, so I can have some function
in between, right there is some function that
145
00:18:38,510 --> 00:18:49,890
I am sampling, this happens to be a fi that
happens to be fi + 1.
146
00:18:49,890 --> 00:18:58,860
What I am doing is; if I look at fi + 1 – fi/
h, so that you get a clear idea so what it
147
00:18:58,860 --> 00:19:06,550
is that we are doing here, right, fi + 1 – fi/
h, this length is h, right just for clarity,
148
00:19:06,550 --> 00:19:16,450
I am actually calculating the slope of that
line; I am calculating the slope of that line.
149
00:19:16,450 --> 00:19:22,000
If I were to take the slope of that line and
assign it and assume let it is the derivative
150
00:19:22,000 --> 00:19:28,740
at the point i, I will be doing forward difference,
right.
151
00:19:28,740 --> 00:19:36,040
And the error that we have; the truncation
error that we have is –h/2 f double prime
152
00:19:36,040 --> 00:19:43,660
at i, if I take the same slope, the same number;
the actual number that you calculated, if
153
00:19:43,660 --> 00:19:50,550
I would take the same slope and assign it
as a derivative at this point at i + 1, right
154
00:19:50,550 --> 00:19:54,820
then I would have backward difference, the
same number, right; the same actual number
155
00:19:54,820 --> 00:19:56,900
that you calculate, it is a backward difference.
156
00:19:56,900 --> 00:20:06,880
And the truncation error would be h/ 2 f double
prime, be careful with this; i + 1 okay and
157
00:20:06,880 --> 00:20:15,420
interestingly, if I take that and assume that
it is the derivative at some midpoint, right
158
00:20:15,420 --> 00:20:21,559
derivative at the midpoint, now my h is not
the same h there, this is right but it still,
159
00:20:21,559 --> 00:20:27,450
I mean it; so 2h actually becomes h in that
formula, so it is the same expression; the
160
00:20:27,450 --> 00:20:33,570
same expression you have to be careful with
the truncation error, okay.
161
00:20:33,570 --> 00:20:39,169
Then the truncation error if I take it as
a central difference for this would turn out
162
00:20:39,169 --> 00:20:50,110
to be h squared/ 24 third derivative, you
can think about that 24, right and this is
163
00:20:50,110 --> 00:20:56,520
at some intermediate point, we do not know
what is that value but it is some intermediate
164
00:20:56,520 --> 00:21:06,850
point i + 1/2 I will just call it i + 1/2,
it is a midpoint. The same number, right is
165
00:21:06,850 --> 00:21:11,960
first order approximation there, first order
approximation there, forward difference, backward
166
00:21:11,960 --> 00:21:15,190
difference this is called central difference,
okay.
167
00:21:15,190 --> 00:21:25,100
So, central difference; the same number central
difference is a better approximation, so that
168
00:21:25,100 --> 00:21:28,830
basically, actually if you think about it,
this should remind you of mean value theorem,
169
00:21:28,830 --> 00:21:34,249
right mean value theorem simply says that
if you are going on a continuous path; if
170
00:21:34,249 --> 00:21:37,309
you are walking on a continuous path right
from one point to another point, if you are
171
00:21:37,309 --> 00:21:41,910
walking on a continuous path from one point
to another point, then somewhere in between
172
00:21:41,910 --> 00:21:46,940
in that trajectory; somewhere in between in
that trajectory, what does mean value theorem
173
00:21:46,940 --> 00:21:47,940
say?
174
00:21:47,940 --> 00:21:51,960
You are walking parallel to the line joining
those 2 points, if you start at a point and
175
00:21:51,960 --> 00:21:58,400
go to another point you understand; if you
start at a point and go to another point,
176
00:21:58,400 --> 00:22:02,120
it does not matter you have all go following
a continuous path somewhere along the line,
177
00:22:02,120 --> 00:22:05,710
you must have been walking along the line
joining those 2 points that is all mean value
178
00:22:05,710 --> 00:22:10,450
theorem says. It does not say where that is
our problem, okay, it does not say, where.
179
00:22:10,450 --> 00:22:19,230
So, this line joining them, this line join;
the function is tangent to it at some point,
180
00:22:19,230 --> 00:22:22,940
the function is tangent, the problem is we
do not know where, we do not know where. If
181
00:22:22,940 --> 00:22:28,140
you give me the point at which it is tangent
then I have the exact derivative at that point,
182
00:22:28,140 --> 00:22:32,660
somewhere in between it is the exact derivative,
here it is an approximation which is first
183
00:22:32,660 --> 00:22:37,260
order; here it is an approximation which is
first order, in between it is an approximation
184
00:22:37,260 --> 00:22:38,260
which is second order.
185
00:22:38,260 --> 00:22:43,850
And at some unknown point, it is an exact
representation somewhere in between for a
186
00:22:43,850 --> 00:22:50,410
continuous function fi + 1 – fi/ h is the
derivative, is that clear okay and it is the
187
00:22:50,410 --> 00:22:53,460
fact that we do not know it that gives us
this truncation error, the fact that we do
188
00:22:53,460 --> 00:22:57,890
not know at what point it is the tangent that
gives us the truncation error, so it is possible
189
00:22:57,890 --> 00:23:03,950
for us to calculate the derivative to approximate
the derivative, to estimate the derivative
190
00:23:03,950 --> 00:23:08,780
at any given point it is possible for us to
estimate the derivative in a given point using
191
00:23:08,780 --> 00:23:12,440
forward differences, central differences,
backward differences.
192
00:23:12,440 --> 00:23:17,100
And the forward difference, backward difference
and central difference have the appropriate
193
00:23:17,100 --> 00:23:22,770
truncation errors, okay; associated truncation
errors, right, so and each one of them, you
194
00:23:22,770 --> 00:23:27,380
will see as we go along there is a reason
why you would use one or the other, okay.
195
00:23:27,380 --> 00:23:37,230
Are there any questions? So, then there comes
the natural next question, if I could use
196
00:23:37,230 --> 00:23:43,660
x + h and x - h to get a second order, right
we are little greedy.
197
00:23:43,660 --> 00:23:50,260
Why do not I take it; is it possible for me
to use the third equation and get one more;
198
00:23:50,260 --> 00:23:55,919
right, a higher order approximation, is it
possible for me to add one more term one more
199
00:23:55,919 --> 00:24:01,210
equation to that and get a higher order approximation
and it is possible, okay. So, I will go back
200
00:24:01,210 --> 00:24:15,230
here, so what happens is something; no, I
want to solve for; I want to solve for f prime,
201
00:24:15,230 --> 00:24:17,520
I want to solve for f prime, okay.
202
00:24:17,520 --> 00:24:23,880
So, just to be careful, I will add one more
term and you allow me to change the notations
203
00:24:23,880 --> 00:24:39,150
slightly, h to the 4th, 4 factorial, f fourth
derivative at i and + h to the 4th/ 4 factorial
204
00:24:39,150 --> 00:24:49,230
f fourth derivative at i, is that okay, fine,
so I am going to go with this subscript i,
205
00:24:49,230 --> 00:24:53,010
though I have left the other terms as x, I
am not going to rewrite the rest of those
206
00:24:53,010 --> 00:24:56,990
equations but you allow me to change to this
notation.
207
00:24:56,990 --> 00:25:03,120
So that f of; you want to take one behind
one ahead we have to decide where to take
208
00:25:03,120 --> 00:25:23,100
it, if I take i - 2 that corresponds to f
of x – 2h, okay, f of i - 2 is f of i – 2h
209
00:25:23,100 --> 00:25:36,059
second derivative; first derivative at i;
got a mistakes, +4 h squared/ 2 second derivative
210
00:25:36,059 --> 00:25:52,270
at i - 8h cube/ 6 third derivative at i +
19/ 24, it is 4 factorial; 4 derivative at
211
00:25:52,270 --> 00:26:15,020
i and so on, it should be possible now for
us to what should we do; how can we go about
212
00:26:15,020 --> 00:26:16,020
this?
213
00:26:16,020 --> 00:26:20,910
What do we want our objective is to make sure
that we retain the first derivative term;
214
00:26:20,910 --> 00:26:28,560
the f prime term, we retain the f prime term,
okay. So, when we had; when we had 2 equations,
215
00:26:28,560 --> 00:26:36,150
we essentially eliminated the f of x and retain
this term, okay and eliminated the f double
216
00:26:36,150 --> 00:26:44,360
prime, the f double prime term, right, we
do not mind having the f of x actually, the
217
00:26:44,360 --> 00:26:50,270
f of x got eliminated as a; right that was
just one of those side things that happen.
218
00:26:50,270 --> 00:26:54,490
What we really want to do is get rid of this,
now in this case I want to get rid of the
219
00:26:54,490 --> 00:27:06,929
third derivative term also. Am I making sense?
It is clear, so you have basically 3 equations
220
00:27:06,929 --> 00:27:22,059
and I want to get f prime of i at i out of
it, how can we do this, what is the deal,
221
00:27:22,059 --> 00:27:33,700
how should we do this? I have a double prime
here; I have a double prime here, okay, so
222
00:27:33,700 --> 00:27:36,350
I want to knock this out, what do I get here?
223
00:27:36,350 --> 00:27:44,360
So, if I take this equation and this equation,
so this is basically 2h squared; 2h squared
224
00:27:44,360 --> 00:27:53,000
or 4/2 is fine, so I need to multiply the
first equation with the; if I multiply this
225
00:27:53,000 --> 00:27:59,590
equation by 4; if I multiply this equation
by 4 and subtract to save the second equation
226
00:27:59,590 --> 00:28:07,630
from the first equation, right that should
get me something. So, if I take this and multiply
227
00:28:07,630 --> 00:28:20,540
it by 4 and subtract this equation from there,
what am I going to get?
228
00:28:20,540 --> 00:28:48,730
4 fi - 1 - fi - 2 equals; 4 fi - 1 - fi - 2
equals 3 or 5 and they have a - and +; -2,
229
00:28:48,730 --> 00:29:04,330
no not -; - 2 h f prime at i, then - i same
minus but I write plus, okay, -2 h f prime
230
00:29:04,330 --> 00:29:11,951
at i + this term and that term are going to
cancel that is the whole objective then I
231
00:29:11,951 --> 00:29:22,920
have 4 of these, I have 8 of those, right;
I have 4 of these, I have 8 of those + 4/6
232
00:29:22,920 --> 00:29:36,320
two thirds h cube f triple prime at i, then
what else? I want to retain the fourth derivative;
233
00:29:36,320 --> 00:29:39,520
I have added the fourth derivative because
it is likely that I suspect that my truncation
234
00:29:39,520 --> 00:29:43,250
error is going to be like the fourth derivative,
right.
235
00:29:43,250 --> 00:29:56,080
So, there are 4 of these and 16 of these,
right; there are 4 of these and of 16 of these
236
00:29:56,080 --> 00:30:13,700
– 12/ 24 fourth derivative of i, fine, h
power 4, most important; h power 4, okay,
237
00:30:13,700 --> 00:30:22,020
so let us taking these 2 and of course earlier
we had knocked out the h squared term by subtracting
238
00:30:22,020 --> 00:30:33,480
these from each other, which gave me fi +
1 - fi - 1 equals, I just repeat that no fi’s
239
00:30:33,480 --> 00:30:56,340
+ 2h f prime at i, this quadratic term cancels
out + 2h cubed/ 6f triple prime at i.
240
00:30:56,340 --> 00:31:02,340
And what happens to the fourth derivative?
Fourth derivative cancels; fourth derivative
241
00:31:02,340 --> 00:31:25,820
cancel + 0, fourth derivative cancels, okay
with move on, what does this give me, what
242
00:31:25,820 --> 00:31:37,100
do I want to do now? I have a 2h f prime here,
which I want to retain but I have a third
243
00:31:37,100 --> 00:31:41,580
derivative term here that I want to eliminate,
I have a third derivative term here that I
244
00:31:41,580 --> 00:31:45,970
want to eliminate, so if I multiply the second
equation by 2; if I were to multiply this
245
00:31:45,970 --> 00:31:54,310
equation by 2, and then do what?
246
00:31:54,310 --> 00:32:01,030
Subtract one from the other okay, so from
maybe the second equation; from this equation,
247
00:32:01,030 --> 00:32:11,250
I subtract that equation, so I get 2 times
fi + 1 - fi - 1 - 4 times fi - 1 - fi - 2
248
00:32:11,250 --> 00:32:36,360
times; 4 times, so I made a mistake, I have
to be bit careful; 4 times fi - 2 - fi – 1,
249
00:32:36,360 --> 00:33:05,090
this gives me - 3 fi +; there is a 2h f prime
and the 4h f prime; 6h f prime at i what else,
250
00:33:05,090 --> 00:33:21,799
the triple prime goes away and we have multiplied
this, so it will be +1/2h to the fourth or
251
00:33:21,799 --> 00:33:38,230
that is + fi – 2, h to the fourth derivative,
right.
252
00:33:38,230 --> 00:33:51,260
Is that okay, fine, so what does this workout
to? I want to solve for the f prime, so I
253
00:33:51,260 --> 00:33:55,460
will take everything else over to the other
side and swap the equations around because
254
00:33:55,460 --> 00:34:22,580
I want the f prime. So f prime at i equals
I have 2fi + 1 - 2fi – 1, then we leave
255
00:34:22,580 --> 00:34:47,830
the 6h here, I do not skip any steps; - 4fi
- 1 + fi - 2 – 3fi; + 3fi + one half h fourth
256
00:34:47,830 --> 00:35:20,290
derivative at i; minus, so clearly I am going
to make a lot of sign errors today okay.
257
00:35:20,290 --> 00:35:41,270
This gives me, somewhere it is add up okay;
2fi + 1+ 3fi – 6fi -1/ 6h – 1/12 h cubed
258
00:35:41,270 --> 00:35:53,230
f to the fourth derivative i, yeah fi, I am
sorry, I should not say fi + 1, where did
259
00:35:53,230 --> 00:36:23,850
I get fi + 1; fi + 1, fi, fi – 1; fi - 2;
fi – 2 - h cube/ 12 f to the fourth derivative,
260
00:36:23,850 --> 00:36:33,790
let me add them up and check that I am performing,
the check; I am performing a test here, you
261
00:36:33,790 --> 00:36:38,960
may not see obvious that the tests that I
am performing is I am adding up the coefficients
262
00:36:38,960 --> 00:36:40,250
in the numerator.
263
00:36:40,250 --> 00:36:48,190
I am adding up the coefficient in the numerator
and in fact they do add up to 0, okay in fact,
264
00:36:48,190 --> 00:36:54,570
they do add up to 0, so here you have some
mechanism by which; you have some mechanism
265
00:36:54,570 --> 00:37:05,390
by which we have got something that has third
order; converges this third order okay and
266
00:37:05,390 --> 00:37:19,550
the representation is third order cubic, is
that fine, has any questions, okay, right.
267
00:37:19,550 --> 00:37:29,140
So, it is possible; so one thing is for the
representation of f prime at x, right can
268
00:37:29,140 --> 00:37:39,410
be represented; can be represented or approximated.
269
00:37:39,410 --> 00:37:42,660
And slowly switch from representing on the
computer to approximating on the computer
270
00:37:42,660 --> 00:37:56,250
represented slash approximated, right using
various points, the sample values at various
271
00:37:56,250 --> 00:38:07,310
point, so you can use fi, i + 1, i + 2, i
- 2 and so on can be represented to apparently
272
00:38:07,310 --> 00:38:18,410
any order that we seek, any order is just
a matter of adding points, as you add points
273
00:38:18,410 --> 00:38:21,839
as you add more and more points right, as
you add more and more points.
274
00:38:21,839 --> 00:38:31,270
So, if you have i +1, i, i -1, i - 2 then
apparently you can get right, very higher
275
00:38:31,270 --> 00:38:36,290
order as higher order as you want, so there
are; it is possible that you can actually
276
00:38:36,290 --> 00:38:42,250
get higher and higher order representations
or approximations okay. So, right now I just
277
00:38:42,250 --> 00:38:47,580
make that as a broad statement, what we need
to do is; we need to find out and we have
278
00:38:47,580 --> 00:38:51,080
this truncation error, everything seems fine
right, everything seems fine.
279
00:38:51,080 --> 00:38:56,900
But you have to little bit careful okay, so
what I do is; I will give you an assignment,
280
00:38:56,900 --> 00:39:07,440
I ask you to you try this out and see what
you get, so we can use this representation
281
00:39:07,440 --> 00:39:13,070
that we have. To check whether we are get;
actually getting it, so pick a function since
282
00:39:13,070 --> 00:39:17,530
we are talking about trig functions in the
last class, I will use sin x.
283
00:39:17,530 --> 00:39:29,750
So, you try out sin of x + h or x + delta
x or whatever, - sin of x/ h, calculate this,
284
00:39:29,750 --> 00:39:36,770
okay, so this is a candidate derivative; this
is a candidate derivative for sin, let us
285
00:39:36,770 --> 00:39:43,280
use; let us assume it is forward differences
so at x right, so this is a candidate derivative
286
00:39:43,280 --> 00:39:54,060
f prime at x, you also know that the derivative
is actually cosine x, pick a value of x, right
287
00:39:54,060 --> 00:40:04,490
pick a value of x, say x equals pi/ 4 and
pick a value of h; pick a value of h, say
288
00:40:04,490 --> 00:40:12,950
h is pi/ 4, okay.
289
00:40:12,950 --> 00:40:21,430
And evaluate this for different values of
h, evaluate this for different values of h
290
00:40:21,430 --> 00:40:40,070
and what I want you to do is; look at cosine
of x - f prime of x/ cosine of x, you can
291
00:40:40,070 --> 00:40:55,990
take either, right take the modulus, if you
want to keep it positive
292
00:40:55,990 --> 00:41:16,760
and what is this? This is some kind of a relative
error, fine okay, so far so good, now this
293
00:41:16,760 --> 00:41:24,750
is what I want you to try to do, you try to
make h smaller and smaller, so in your program
294
00:41:24,750 --> 00:41:27,760
you keep having the value of h.
295
00:41:27,760 --> 00:41:36,840
So, you say h is 0.5 times h in your program,
you keep having the value of h and keep calculating
296
00:41:36,840 --> 00:41:47,400
this relative error and I want you to plot
on a log log plot; on a log log plot, I want
297
00:41:47,400 --> 00:42:01,099
you to plot the relative error, this is h,
is it okay, is that fine, okay. So, now that
298
00:42:01,099 --> 00:42:08,640
is clear, you tell me what you expect, now
that the assignment is clear, what do you
299
00:42:08,640 --> 00:42:17,290
expect? I want you to try it for different
schemes, that is I want you to do it for forward
300
00:42:17,290 --> 00:42:20,520
difference, backward difference, central difference.
301
00:42:20,520 --> 00:42:27,210
What is it that you expect? Remember h grows
larger in this direction, h grows larger in
302
00:42:27,210 --> 00:42:32,030
this direction that means you are starting
somewhere here that is pi/ 4 and you are going
303
00:42:32,030 --> 00:42:41,060
to work your way towards 0, okay. How many
times are you going to divide by 2; how many
304
00:42:41,060 --> 00:42:52,080
times are you going to; how many values of
h are you going to try this, h; weather h
305
00:42:52,080 --> 00:42:55,480
should be below machine epsilon or whatever
it is you figure out whether it should be
306
00:42:55,480 --> 00:42:57,089
does it have to be below machine epsilon.
307
00:42:57,089 --> 00:43:03,109
Let it you do it just see what happens, right
so what is it that you expect? Say for a first
308
00:43:03,109 --> 00:43:09,140
order; for a first order scheme for a forward
difference, this is forward difference, what
309
00:43:09,140 --> 00:43:14,720
is it that you expect, what do you expect
the graph to look like? You expect a linear
310
00:43:14,720 --> 00:43:25,579
curve, linear curve like that something like
that, try it out and see what you get, right
311
00:43:25,579 --> 00:43:35,859
and if it is second order; if it is second
order, now you would be careful, it is second
312
00:43:35,859 --> 00:43:37,190
order it is still going to be linear.
313
00:43:37,190 --> 00:43:43,131
This was a 45 degree line, second order will
be; you expect the steeper line, is it go
314
00:43:43,131 --> 00:43:50,270
through the origin I do not get it, some problem
or maybe it starts somewhere else, I do not
315
00:43:50,270 --> 00:43:55,810
know if I am making sense, you are taking
log on both sides, you have log error, relative
316
00:43:55,810 --> 00:44:00,109
error equals whatever look at the truncation
error work this out, you try to work it out,
317
00:44:00,109 --> 00:44:05,359
we will get back, we will take a look at it,
try to work it out okay, try to work it out.
318
00:44:05,359 --> 00:44:10,010
And as I warned you before always some little
trap in something that I asked you to do,
319
00:44:10,010 --> 00:44:18,030
so keep your eyes open, okay. So, having this
maybe you know try 64 times possibly, it is
320
00:44:18,030 --> 00:44:28,810
a lot, rate of 50 times, try having it 50
times, okay that should not get you into trouble,
321
00:44:28,810 --> 00:44:36,020
try having it 50 times, try it for float and
double; float double, you try long double,
322
00:44:36,020 --> 00:44:42,690
okay try a combination and see what happens,
is that fine, okay right.
323
00:44:42,690 --> 00:44:56,619
So, let us get back to this as it turns out
we are able to get derivatives of; we are
324
00:44:56,619 --> 00:45:04,810
able to get; we are able to get derivatives
of various orders approximations to a derivative;
325
00:45:04,810 --> 00:45:09,231
first derivative of various orders, so can
we get second derivatives, right. So, we look
326
00:45:09,231 --> 00:45:13,820
at these 2 equations and in fact, it turns
out we can get a second derivative, if you
327
00:45:13,820 --> 00:45:17,890
just add the 2 equations, it is clear now
that these terms will cancel.
328
00:45:17,890 --> 00:45:27,950
So, we have f of x + h, which is f of i +
1 + f of x – h, which is f of i – 1, as
329
00:45:27,950 --> 00:45:41,900
2 times f of x, which is f of i; fi, this
term cancels + h squared/ 2 goes away f double
330
00:45:41,900 --> 00:45:54,920
prime at i which is what we want, this term
cancels, leaving us 2 of these + 1/12 h to
331
00:45:54,920 --> 00:46:04,990
the fourth derivative at i and there are higher
order terms, we can solve for the second derivative
332
00:46:04,990 --> 00:46:23,910
and therefore the second derivative at i equals
fi + 1 - 2fi + fi – 1/ h squared.
333
00:46:23,910 --> 00:46:37,579
And the truncation error is – 1/12 h squared
fourth derivative at i okay that is the truncation
334
00:46:37,579 --> 00:46:46,160
error, is that fine. I wanted to; so it pretty
actually, one I wanted to do it today because
335
00:46:46,160 --> 00:46:51,620
it is straightforward, the expression is here
we can just subtract, get the second derivative,
336
00:46:51,620 --> 00:46:56,200
it is possible to get the second derivative
in terms of i, i + 1, i – 1 and so on. I
337
00:46:56,200 --> 00:46:59,810
also wanted to do it because I wanted to make
one thing here.
338
00:46:59,810 --> 00:47:05,500
What is the rate at which the truncation error
goes to 0? H squared, it is quadratic, it
339
00:47:05,500 --> 00:47:11,119
is second order, right, second order. What
is the polynomial that we can for which we
340
00:47:11,119 --> 00:47:18,359
can get the answer, let us cubic, right, so
I do not want you to get in your mind that
341
00:47:18,359 --> 00:47:22,150
the function representation is quadratic,
convergence is quadratic you write that was
342
00:47:22,150 --> 00:47:27,380
only for first derivatives. When you go to
second derivatives, the error term converges
343
00:47:27,380 --> 00:47:28,790
as h squared.
344
00:47:28,790 --> 00:47:33,790
But the order of the representation of the
function, you understand the order of the
345
00:47:33,790 --> 00:47:39,609
representation, right is the fourth derivative;
the fourth derivative and therefore you can
346
00:47:39,609 --> 00:47:48,650
represent a cubic exactly, is that make sense,
right. So, only if you plug in a fourth degree
347
00:47:48,650 --> 00:47:53,810
polynomial will this be nonzero, okay. So,
even for the third degree polynomial let us
348
00:47:53,810 --> 00:47:58,220
going to work but this convergence is second
order, okay.
349
00:47:58,220 --> 00:48:02,849
Right, just because for the first derivative
approximations they seem to match, i do not
350
00:48:02,849 --> 00:48:06,180
want you to get in your mind they matched
because we were dividing by h but here we
351
00:48:06,180 --> 00:48:10,839
are dividing by h squared and I suspect looking
at this that maybe for third derivatives we
352
00:48:10,839 --> 00:48:18,940
end up dividing by h cube, okay, so that is
one thing to remember, so you have a h squared
353
00:48:18,940 --> 00:48:25,900
order of convergence, representation is cubic
for the function, is that fine, okay.
354
00:48:25,900 --> 00:48:39,660
So, it is clear using the values of the function
at various locations that we can actually
355
00:48:39,660 --> 00:48:44,839
approximate derivatives, right. So, we are
now in a position to actually approximate
356
00:48:44,839 --> 00:48:50,410
differential equations, is that fine, right.
So, we now; once we are able to approximate
357
00:48:50,410 --> 00:48:54,569
functions, once we are able to approximate
derivatives, we are in a position to approximate
358
00:48:54,569 --> 00:48:58,760
differential equation, we can approximate
the differential equations and actually represent
359
00:48:58,760 --> 00:49:02,380
our functions on the computer and systematically
hunt for the solution, okay.
360
00:49:02,380 --> 00:49:09,231
So, this we will do in the next class, what
we are going to do is; you look at an equation
361
00:49:09,231 --> 00:49:14,800
in 2 dimensions, so all my derivations are
in 1D, I am going to look at the equations
362
00:49:14,800 --> 00:49:20,940
in 2D but before I finish, I just want to
emphasize some terms that I am using. So,
363
00:49:20,940 --> 00:49:32,540
these are; if i – 1, i, i + 1, i + 2 and
so on, you will see me refer to these, this
364
00:49:32,540 --> 00:49:37,290
whole interval being broken up into a mesh
or a grid.
365
00:49:37,290 --> 00:49:45,300
I will explain these terms more detail later
and these points I will typically refer to
366
00:49:45,300 --> 00:49:50,839
them as grid points but you may hear people
referring to them as nodes okay, right. So,
367
00:49:50,839 --> 00:49:58,040
I will typically referred to them as grid
points. So, given function values at grid
368
00:49:58,040 --> 00:50:02,970
points were able to represent functions, were
able to represent derivatives and therefore
369
00:50:02,970 --> 00:50:09,730
we will be able to represent on those on that
mesh a differential equation, right.
370
00:50:09,730 --> 00:50:15,579
Because they are able to represent derivatives
and also extract out a solution, which you
371
00:50:15,579 --> 00:50:20,710
are able to represent on that mesh, is that
fine okay that is our objective, fine, next
372
00:50:20,710 --> 00:50:21,869
class thank you.