I was planning on covering all the topics in numerical methods in the Lecture notes though the pace of this class is about 10 times faster than I expected, and so covering everything would be redundant and tedious.
Thus, this post exists. Ideally I’ll be documenting about 3 weeks of content into a single post, every 3 weeks.
Many of the topics in numerical methods tend to be very similar, which is probably partly responsible for the rapid pace. Recognising these similarities will make it unreasonably easier to digest the content.
Rejoice classmates.
Taylor Polynomials
There’s lots of different notational ways to display taylor series.
A good starting point would be
f(x)≈f(a)+f′(a)(x−a)+2!f′′(a)(x−a)2+⋯+n!f(n)(a)(x−a)n.
Notice that the first term f(a) and f′(a) follow the same pattern as the rest of the series when starting at n=0, so it simplifies nicely while the third term (n=2) keeps the redundant 2! to display the reoccuring pattern.
Now writing this out can get tedious so we’ll use summation notation and recognise that eqref(1) is equal to
n=0∑Mn!f(n)(a)(x−a)n,
where f(n)(a) is the nth derivative of the function and M∈Z+.
With this, we can find polynomials of degree n that approximate f(x).
To do this, we need to choose a function we want to approximate, some element a∈R (or C, though I won’t be covering the complex case)
and the degree of the polynomial. We’ll denote the degree of the polynomial to be Pn(x), hence, for example,
P2(x)=f(a)+f′(a)(x−a)+2!f′′(a)(x−a)2.
Given the data, the standard is to first check the degree of the polynomial you want to use to approximate the function.
Say we chose a degree of order 4, i.e. P4(x). Then we would look at the given function and get it’s derivatives up to four. That is, f′(a),f′′(a),f′′′(a),f(4)(a).
Next we would plug in our values into P4(x), specifically, the value of a and the derivatives. After evaluating P4(x) we note that
P4(x)≈f(x)
Meaning we can approximate any value of f(x) (that the function allows), such as f(3) by computing P4(3) instead. And so we are done.
If you happened to choose a=0 you may have noticed that it’s the Maclaurin Series.
Looking back at eqref(1), there is a small subletly in the ≈ symbol. If the function we are “approximating” is a polynomial, then we can always get the exact function after finitely many steps; this isn’t the case for non-polynomial functions such as ex for example.
Taylor’s error
Recall that
f(x)=n=0∑∞n!f(n)(a)(x−a)n.
This gives us the exact function, though we can’t compute an infinite amount of terms on a computer. So how do we get know when our approximation has enough accuracy?
though without an error term, we don’t really know how well our polynomial approximates the point of a function. Thus we have
Rn(x), the remainder/error term
Rn(x)=(n+1)!f(n+1)(ξ)(x−a)n+1
where f(n+1)(ξ) is the (n+1)th derivative of f at ξ.
Also x≤ξ≤a. Equivalently ξ is a point ξ∈[x,a].
At first glance this formula might seem like it’s come out of nowhere, but it’s a term added onto Pn(x) following the same pattern which can be seen below.
f(x)==f(a)+f′(a)(x−a)+2!f′′(a)(x−a)2+⋯+n!f(n)(a)(x−a)n+(n+1)!f(n+1)(ξ)(x−a)n+1k=0∑nk!f(k)(a)(x−a)k+Rn(x).
If you’re familiar with factorials, you may have realised that Rn(x) can be written in the terms of the gamma function:
Rn(x)=Γ(n+2)f(n+1)(ξ)(x−a)n+1,
because Γ(n+2)=(n+1)! for n∈Z+. Why would you want to use this? I don’t know, but you can if you want.
Actually obtaining the exact value of Rn(x) pretty much never happens in practice, rather, we use it to find the maximum error ∣Rn(x)∣, by choosing the smallest value of ξ possible, but since we don’t know ξ we can’t do that, which is why the interval ξ∈[x,a] is how we end up choosing a suitable ξ.
Lagrange polynomials
In Lagrange form, we can find a polynomial lk(x) of degree n by
lk(x)=(xk−x0)…(xk−xk−1)(xk−xk+1)…(xk−xn)(x−x0)…(x−xk−1)(x−xk+1)…(x−xk)
so that
lk(xi)={01if i=kif i=k.
The interpolating polynomial
Pn(x)=l0(x)y0+l1(x)y1+⋯+lk(x)yk+⋯+ln(x)yn=k=0∑nlk(x)yk.
Note that Pn(xj)=yj. because Pn(xj)=yj=0+⋯+0+lj(xj)yj+0+⋯+0=yj.
Now to find the interpolating polynomial we need x and y values. For some questions you won’t get both x and y values, but rather a function and just x−values, for those cases, you evaluate the functions by plugging in each xi value to get all yi values before continuing.
Now the general method for finding Pn(x) using lagrange polynomials can get tedious by hand, luckily there is a pattern which can speed up the process.
Setting πn(x)=(x−x0)(x−x1)…(x−xn) and πn′(xk)=∏i=0,i=k(xk−xi), for k=0,…,n,
let’s us rewrite lk(x) as (x−xk)πn′(xk)πn(x).
This is nice because (x−xk) in the denominator of lk(x) always cancels out. So l0(x),l1(x),…,ln(x)
will always be of the form
l0(x)=πn′(x0)(x−x1)(x−x2)(x−x3)(x−x4)…(x−xn)l1(x)=πn′(x1)(x−x0)(x−x2)(x−x3)(x−x4)…(x−xn)l2(x)=πn′(x2)(x−x0)(x−x1)(x−x3)(x−x4)…(x−xn)l3(x)=πn′(x3)(x−x0)(x−x1)(x−x2)(x−x4)…(x−xn)⋮ln(x)=πn′(xn)(x−x0)(x−x1)(x−x2)(x−x3)(x−x4)…(x−xn−1).
This let’s us obtain Pn(x) without getting lost in the details.
Newtons divided differences
This part is a bit boring and tedious to write all out, so I’ll explain a geometric way of thinking about it, if you care for the details Wikipedia gives the gist.
We want to create a divided difference table to evaluate Pn(x) by using a set of points, while making sure our Pn(x) fits through the points.
i⋮0⋮1⋮2⋮3⋮n⋮xi⋮∙∙∙∙⋮∙yi⋮∙∙∙∙⋮∙D1⋮×∙∙∙⋮∙D2⋮××∙∙⋮∙⋯⋮⋯⋯⋯…⋱⋯Dn⋮×××⋮⋮∙
Suppose we were given the points x=(0,1,2,3,4,5) and y=(0,1,4,15,40,85). So x0=0,x1=1,x2=2, etc. and y0=0,y1=1,y2=4,etc. Then using the newtons’s divided difference table we could find a polynomial which passes through the points
(x,y)=((0,0),(1,1),(2,4),(3,15),(4,40),(5,85)).
There are many different ways to reach this polynomial. One way is to just compute
Pn(x)=f[x0]+(x−x0)f[x0,x1]+(x−x0)(x−x1)f[x0,x1,x2]+⋯+(x−x0)(x−x1)⋯(x−xn−1)f[x0,x1,…,xn].
Though as you can see, this can get quite messy, and while we know the values of f[x0], we still don’t know f[x0,x1],f[x0,x1,x2] etc., so before we can compute Pn(x) we need to find those values. Though the notation is getting a bit annoying. We can simplify this by assigning each f[x0,…,xn] with a variable a, so that f[x0]=a0, f[x0,x1]=a1, f[x0,x1,x2]=a2 and so forth:
Pn(x)=a0+(x−x0)a1+(x−x0)(x−x1)a2+⋯+(x−x0)(x−x1)…(x−xn−1)an=a0+i=1∑naij=0∏i−1(x−xj)
Below is an example of how I would geometrically solve the divided difference table, to avoid the influx of notation.The hollow-yellow boxes are the values a0,a1,…,a6 respectively. The full-blue box is the value currently being evaluated. The full-yellow boxes are the values used to compute the full-blue value.
Explaining the procedure is pretty awkward so just look at the animation and see if you can see what I’m doing. Otherwise solve the newton’s divided difference table however you like, there’s plenty of different setups and tables you can find online that do this.

Now that the table has been complete, we know that a=(0,1,1,1,0,0), so we can plug these values along with all the xi values into Pn(x) to get the polynomial. In general you won’t get
nice values like the one in the animation, those values were chosen specifically for simplicity sake.You may be worried about what to do if the procedure leads to a division by zero. For such cases you take the derivative of the function instead of the standard algorithmic process.
This means that just the (x,y) points aren’t enough for such cases, since you won’t be able to get a derivative of a function with just points. In fact, hermite interpolation is a special case of this.
Hermite Interpolation
Given the function f(x)=x4+x3−x and the points (x,y)=((−1,1),(0,0),(1,1)), find P5(x). Below can be used for reference for how I would complete the divided difference table.
Notice that for hermite interpolation,
it’s pretty much the exact same as the above example, just that we need a function to compute the derivatives because we have to repeat each xi and yi twice in their respective columns.
This is because the hermite polynomial approximation is
P2n+1=a0+i=1∑2n+1aij=0∏i−1(x−xj).
Similarly to lagrange’s error term, the hermite polynomials error term is
R2n+1(x)=f(x)−P2n+1(x)=(π(x))2(2n+1)!f(2n+1)(ξ).
Again, you can also write (2n+1)! in terms of the gamma function if you want to for whatever reason.
π(x) here again refers to (x−x0)…(x−xn).
To find a bound using the error term, you first find the hermite polynomial, and plot it specify the max for the function, then use that to get the an inequality, that is the bound of the error, similar to how we obtain Taylor’s error bound.
And that’s it for now. Bye.