Numerical Differentiation
Problem Defined
In many practical applications, we may want the derivative of a function , without evaluating the true expression for . This may occur because:
- The true expression for is extremely complicated, or expensive to compute!
- We only have points for - , so we don’t even have an expression for to compute a derivative with!
How can we find such derivatives?
Derivations Using Taylor Approximations
One way we can derive an iterative solution for derivatives is by using their Taylor Approximation!
For example, recall that
If and is very small, we approximately have that
By the Taylor Remainder Theorem of about , we have that for some ,
Where is the error value on , which converges to 0 as h becomes small. This has a order error, and approximates our derivative from the left-hand side, known as the forward difference!
Orders of Error
For any error term , we say that it is a order method (), where is the leading power term (lowest exponent) of in , as the lowest exponent will contribute the most to the error.
The higher the order of error, the better!
We similarly have a backward difference,
which essentially approximates our derivative from the right-hand side (with order of error), and a central difference,
which approximates our derivative using both sides. We can show that this error term has a order of error, making it better than the previous two!
Central Difference for
We also can find a central difference for as
Which similarly has an error term for .
In general, we have for any , that there exists
We can use combinations of these Taylor expansions to approximate our derivatives!
Derivations Using Undetermined Coefficients
Sometimes, simple Taylor expansions are not enough - in these cases, we may still be able to approximate our derivative using the method of undetermined coefficients! In such a problem, we are given the following values
where , , and want to find a linear combination of these values to approximate some derivative . We then use their Taylor expansions to solve for the coefficients.
To see how this is done, consider the following example.
Say we want to approximate using a linear combination of . Then, we can approximate it as
We expand each using their Taylor Expansions (performed above) to obtain
We now attempt to find necessary to find our answer. As we want our second derivative, we want to drop the coefficients for our and terms to 0, but make the coefficient for the term 1!
We solve this as
Subbing this back into our equation, we get
Which we can use to approximate our value!
Rates of Convergence
Given an approximation of , the error is given as
Suppose the error is approximately equal to , where is a constant, indicating that it is a order method.
If we take the logarithm of this error, we obtain
We can use this fact to to find our order of error (rate of convergence)! So, given our error on ,
We can find our order of error as
Richardson’s Extrapolation
Richardson’s Extrapolation describes a general method to boost the accuracy of our approximations.
Consider the order approximation
Where is our target, is our algorithm, and every is part of the error term.
Note that if we wanted to change the order of our approximation, we’d need to eliminate the term.
Consider what happens if we replace with .
Then, we can use this equation to elminate our error term. Multiplying our first equation by and subtracting our second equation from it, we get
Giving us a new algorithm that increases our order of error!
Numerical Integration
In other practical applications, we may want the integral of a function , . This may occur because
- We may not know in order to take the integral.
- We may know , but a closed form expression of the integral may not be available.
- We may be able to compute the integral, but it is difficult to compute.
- We may only have at a few nodes!
To do these approximations, we’ll perform what are known as quadrature rules, rules that let us approximate integrals.
Integration via Interpolation
Possibly one of the more intuitive approaches to approximations is to first interpolate given its points, and then integrate this interpolation.
Assume we’re given points , where , . Recall that for these points, we can find our Lagrange Polynomial as
Where are the bais polynomials. Then, as this approximates , we may also be able to approximate its integral using !
This can alternatively be given as
Similar to our Lagrange Interpolation, this has an advantage in that we can save on a lot of computation for different functions on the same nodes!
Note that this is essentially taking a “weighted sum”, as the integrals define a value determining how much each contributes to the result.
We discuss various ways we can use this below!
Closed Newton-Cotes Quadrature
Suppose we have our equipspaced interpolation nodes on , given by
Where . Note that by this, , and .
Then, using our integral approximation from before, we’ll obtain approximation
Theorem: Error
There exists a such that
Note that this error is 0, meaning this quadrature is exact if is a polynomial such that
- It’s degree if is even
- It’s degree if is odd
As in these cases, the derivative in the error term drops to 0.
Some important quadratures from this rule are given below.
- When , we have the Trapezoidal rule, giving us
- When , we have the Simpson’s rule, giving us
Open Newton-Cotes Quadrature
Suppose we have a set of nodes , such that ,
Where . Note that by this definition, , and .
Then, for some , we obtain
Note that we have exactness if is a polynomial under the same conditions as the closed-form algorithm.
Some important quadratures from this rule are given below.
- When , we have the Midpoint rule, giving us
This takes the integral of a constant line, whose value is equal to ‘s midpoint.
Composite Quadrature Rules
In each of these quadrature rules, because our errors depend on , as , , giving us lower errors! So, we should interpolate with higher-degree polynomials, right?
Wrong! As we use higher-degree polynomials, we run into another issue - Runge’s Phenomena! So, to minimize our errors, we should use other methods (as described below).
One such method is by applying a composite quadrature rule, which partitions into smaller intervals and applies lower-order quadrature rules on each. So, given , we’ll have partition
And can apply our quadrature rules on each subinterval with size , whose composite will form our function integral.
Each subquadrature is given as
Where are the quadrature weights on , and are the quadrature nodes in our subinterval. For each subquadrature, we commonly will apply our midpoint rule, trapezoidal rule, or simpson’s rule.
Suppose we applied our midpoint rule. We can prove that our new error is of order 2!
Proof
For simplicity, assume that the size of our subintervals is constant. Then, if we applied our midpoint rule, for any subinterval, we get error term
For some in our subinterval. Then, our total composite error is given as
Defining , the average of these node values, we know that this average is bounded by ‘s maximum and minimum along the entire interval! So, we can apply intermediate value theorem to find a such that .
This gives us error
For some in our interval . Applying our assumption that , we get
Telling us that our error term is a 2nd order method!
We can similary find that the composition trapezoidal rule is a 2nd order method, and our composition simpson’s rule is a 4th order method.
Romberg Integration
Similarly to how we have Richardson’s Extrapolation for boosting accuracy, we can also apply something known as Romberg Integration to boost the accuracy of composite integration.
Applying a similar process to Richardson’s Extrapolation, we obtain
Giving us a new quadrature which is of a higher order error!
However, we need to be a bit careful with this - replacing by means we’re halving the number of subintervals we have for this second quadrature! This is only possible if is even, as otherwise, we won’t be able to evenly cover our entire domain.
Doing this also means we have to evaluate at different points, which are actually where the partition boundaries once were!
Gaussian Quadratures
Note that in the prior quadrature rules, we formed approximations of the form
Where our quadrature nodes are given.
How do we pick the quadrature nodes and quadrature weights such that our approximate is exact for the maximal degre of polynomials?
Example: Exact Quadratures
The quadrature rule
Is exact on .
So, suppose we have quadrature nodes and quadrature weights. This gives us unknowns! Thus, it may be possible to exactly represent polynomials in .
Note that any polynomial can be expressed as
So, our rule is exact on if it is equal to the integral of this!
Below, we state a theorem to help us determine what nodes and weights we should be choosing.
Theorem: Properties of Orthogonal Functions
If is a non-zero function on such that
- is orthogonal to , or in other words
Then, will change sign at least times in - it has at least real distinct zeroes in .
Theorem: Exactness of Quadrature Rules
Let be a polynomial satisfying the following properties:
- and is of the degree .
- is orthogonal to .
- has real, simple roots, and all roots are in .
Then, the quadrature rule with these roots as the quadrature nodes and the quadrature weights
Is exact on .
Proof
Let . By property of polynomials, we can factorize as
Where is a polynomial of most satisfying the above theorem, and and are polynomials of at most .
At the roots of (which are guaranteed by the above theorem), we have
Taking the integral of , we have
So, if we can find such a polynomial , we can find exactness!
How can we find such a ?
Recall the Legendre Polynomials on , which are orthogonal
These polynomials have the following properties:
- The degree of each polynomial is .
- is orthogonal to .
- By an earlier theorem, has distinct, real roots on .
So, on , we can choose to be the Legendre polynomial on !
We can, in fact, find our earlier example using !
Example: Exact Quadratures
Recall
This is exact on , so , so we choose .
We have roots at and . We choose these to be our quadrature nodes. We then have
Thus, our exact quadrature rule is , giving us the above!
What if our interval isn’t ? Then, we can apply a change of variables!
If , then we can set
transforming our domain into the interval ! This gives us integral
We can use this to find the roots of in , and convert them to the quadrature nodes !