BCA Numerical Method
BCA Numerical Method
Under Guidance of
BISECTION METHODE
1. Find points a and b such that a < b and f(a) * f(b) < 0.
2. Take the interval [a, b] and find its midpoint x1.
3. If f(x1) = 0 then x1 is an exact root, else if f(x1) * f(b) < 0 then let a = x1, else
if f(a) * f(x1) < 0 then let b = x1.
4. Repeat steps 2 & 3 until f(xi) = 0 or |f(xi)| <= DOA, where DOA stands for
degree of accuracy.
5. For the ith iteration, where i = 1, 2, . . . , n, the interval width is
6. xi = 0.5
xi–1 = ( 0.5 )i ( b – a )
7. and the new midpoint is
8. xi = ai–1 + xi
1 1 1.5 2 –1 2.875 9
–
8 1.1484375 1.15234375 1.15625 –0.0127759575843811 0.014556884765625
0.0400032997131348
–
9 1.15234375 1.154296875 1.15625 0.000877253711223602 0.014556884765625
0.0127759575843811
____________________________________________________
2.REGULA-FALSI METHOD
The convergen process in the bisection method is very slow. It depends only on the choice of end
pointsof the interval [a,b]. The function f(x) does not have any role in finding the point c (which
is just the mid-point of a and b). It is used only to decide the next smaller interval [a,c] or [c,b].
A better approximation to c can be obtained by taking the straight line L joining the points
(a,f(a)) and (b,f(b)) intersecting the x-axis. To obtain the value of c we can equate the two
expressions of the slope m of the line L.
f(b) - f(a) 0 - f(b)
m= =
(b-a) (c-b)
f(b) * (b-a)
c=b-
f(b) - f(a)
Now the next smaller interval which brackets the root can be obtained by checking
Selecting c by the above expression is called Regula-Falsi method or False position method
of the interval is getting smaller in each iteration, it is possible that it may not go to zero. If the
graph y = f(x) is concave near the root 's', one of the endpoints becomes fixed and the other end
marches towards the root.
EXAMPLE:
Find the root between (2,3) of x3+ - 2x - 5 = 0, by using regular falsi method.
Given
f(x) = x3 - 2 x - 5
f(2) = 23 - 2 (2) - 5 = -1 (negative)
f(3) = 33 - 2 (3) - 5 = 16 (positive)
Let us take a= 2 and b= 3.
The first approximation to root is x1 and is given by
x1 = (a f(a) - b f(b))/(f(b)-f(a))
=(2 f(3)- 3 f(2))/(f(3) - f(2))
=(2 x 16 - 3 (-1))/ (16- (-1))
= (32 + 3)/(16+1) =35/17
= 2.058
Taking a = 2.058 and b = 3. we have the second approximation to the root given by
x2 = (a f(a) - b f(b))/(f(b)-f(a))
= (2.058 x f(3) - 3 x f(2.058)) /(f(3) - f(2.058))
= (2.058 x 16 -3 x -0.4) / (16 - (-0.4))
= 2.081
____________________________________________________
3.Newton-Raphson:
In numerical analysis, Newton's method (also known as the Newton–Raphson method or the
Newton–Fourier method) is an efficient algorithm for finding approximations to the zeros (or
roots) of a real-valued function. As such, it is an example of a root-finding algorithm.
Any zero-finding method (Bisection Method, False Position Method, Newton-Raphson, etc.) can
also be used to find a minimum or maximum of such a function, by finding a zero in the
function's first derivative, see Newton's method as an optimization algorithm.
Example
Let's consider f(x)=x2-a. Here, we know the roots exactly, so we can see better just how well the
method converges.
We have
This method is easily implemented, even with just pen and paper, and has been used to rapidly
estimate square roots since long before Newton.
If a>0, en+1 will be positive, provided en is greater than -√a, i.e provided xn is positive. Thus,
starting from any positive number, all the errors, except perhaps the first will be positive.
This method converges to the square root, starting from any positive number, and it does so
quadratically.
____________________________________________________
<1>Gauss Elimination Method
DEFINITION 2.2.10 (Forward/Gauss Elimination Method) Gaussian elimination is a method
of solving a linear system (consisting of equations in unknowns) by bringing the
augmented matrix
Solution: In this case, the augmented matrix is The method proceeds along the
following steps.
The last equation gives the second equation now gives Finally the first equation
Solution: In this case, the augmented matrix is and the method proceeds as
follows:
<2>Jacobi method
In numerical linear algebra, the Jacobi method is an algorithm for determining the solutions of a system
of linear equations with largest absolute values in each row and column dominated by the diagonal
element. Each diagonal element is solved for, and an approximate value plugged in. The process is then
iterated until it converges. This algorithm is a stripped-down version of the Jacobi transformation
method of matrix diagonalization. The method is named after Carl Gustav Jakob Jacobi.
where:
Then A can be decomposed into a diagonal component D, and the remainder R:
Note that the computation of xi(k+1) requires each element in x(k) except itself. Unlike the Gauss–
Seidel method, we can't overwrite xi(k) with xi(k+1), as that value will be needed by the rest of the
computation. The minimum amount of storage is two vectors of size n.
Further, C is found as
This process is repeated until convergence (i.e., until is small). The solution after
25 iterations is
<3>Gauss–Seidel method
In numerical linear algebra, the Gauss–Seidel method, also known as the Liebmann method or
the method of successive displacement, is an iterative method used to solve a linear system of
equations. It is named after the German mathematicians Carl Friedrich Gauss and Philipp
Ludwig von Seidel, and is similar to the Jacobi method. Though it can be applied to any matrix
with non-zero elements on the diagonals, convergence is only guaranteed if the matrix is either
diagonally dominant, or symmetric and positive definite.
Description
where:
Then A can be decomposed into a lower triangular component L*, and a strictly upper triangular
component U:
The Gauss–Seidel method is an iterative technique that solves the left hand side of this
expression for x, using previous value for x on the right hand side. Analytically, this may be
written as:
However, by taking advantage of the triangular form of L*, the elements of x(k+1) can be
computed sequentially using forward substitution:
Note that the sum inside this computation of xi(k+1) requires each element in x(k) except xi(k) itself.
The procedure is generally continued until the changes made by an iteration are below some
tolerance.
and
in the form
where:
and
We must decompose into the sum of a lower triangular component and a strict upper
triangular component :
and
First of all, we have to choose : we can only guess. The better the guess, the quicker the
algorithm will perform.
We suppose:
Suppose we choose (0, 0, 0, 0) as the initial approximation, then the first approximate solution is
given by
Using the approximations obtained, the iterative procedure is repeated until the desired accuracy
has been reached. The following are the approximated solutions after four iterations.
and
in the form
where:
and
We must decompose into the sum of a lower triangular component and a strict upper
triangular component :
and
Now we have and and we can use them to obtain the vectors iteratively.
First of all, we have to choose : we can only guess. The better the guess, the quicker will
perform the algorithm.
We suppose:
Unit-2
Newton-Raphson
In numerical analysis, Newton's method (also known as the Newton–Raphson method or the
Newton–Fourier method) is an efficient algorithm for finding approximations to the zeros (or
roots) of a real-valued function. As such, it is an example of a root-finding algorithm.
Any zero-finding method (Bisection Method, False Position Method, Newton-Raphson, etc.) can
also be used to find a minimum or maximum of such a function, by finding a zero in the
function's first derivative, see Newton's method as an optimization algorithm.
The idea of the Newton-Raphson method is as follows: one starts with an initial guess which is
reasonably close to the true root, then the function is approximated by its tangent line (which can
be computed using the tools of calculus), and one computes the x-intercept of this tangent line
(which is easily done with elementary algebra). This x-intercept will typically be a better
approximation to the function's root than the original guess, and the method can be iterated.
Suppose f : [a, b] → R is a differentiable function defined on the interval [a, b] with values in the
real numbers R. The formula for converging on the root can be easily derived. Suppose we have
some current approximation xn. Then we can derive the formula for a better approximation,
xn+1 by referring to the diagram on the right. We know from the definition of the derivative at a
given point that it is the slope of a tangent at that point.
We can get better convergence if we know about the function's derivatives. Consider the tangent
to the function:
Near any point, the tangent at that point is approximately the same as f('x) itself, so we can use
the tangent to approximate the function.
The next approximation, xn+1, is where the tangent line intersects the axis, so where y=0.
Rearranging, we find
Example:-
Case II. The second root lies between (0,1) Root lies between 0 and I
Second app.
(1)
(2)
(3)
Here, the column vector in the variables is carried along for labeling the matrix rows. Now,
perform elementary row operations to put the augmented matrix into the upper triangular form
(4)
Solve the equation of the th row for , then substitute back into the equation of the st row
to obtain a solution for , etc., according to the formula
(5)
GaussianElimination[m_?MatrixQ, v_?VectorQ] :=
Last /@ RowReduce[Flatten /@ Transpose[{m, v}]]
(6)
(7)
Switching the first and third rows (without switching the elements in the right-hand column
vector) gives
(8)
Subtracting 9 times the first row from the third row gives
(9)
Subtracting 4 times the first row from the second row gives
(10)
Finally, adding times the second row to the third row gives
(11)
(12)
Jacobi Method
The Jacobi method is a method of solving a matrix equation on a matrix that has no zeros along
its main diagonal (Bronshtein and Semendyayev 1997, p. 892). Each diagonal element is solved
for, and an approximate value plugged in. The process is then iterated until it converges. This
algorithm is a stripped-down version of the Jacobi transformation method of matrix
diagonalization.
The Jacobi method is easily derived by examining each of the equations in the linear system of
equations in isolation. If, in the th equation
(1)
solve for the value of while assuming the other entries of remain fixed. This gives
(2)
In this method, the order in which the equations are examined is irrelevant, since the Jacobi
method treats them independently. The definition of the Jacobi method can be expressed with
matrices as
(3)
where the matrices , , and represent thediagonal, strictly lower triangular, and strictly
upper triangular parts of , respectively.
we determine as
Further, C is found as
This process is repeated until convergence (i.e., until is small). The solution after
25 iterations is
Gauss-Seidel Method
The Gauss-Seidel method (called Seidel's method by Jeffreys and Jeffreys 1988, p. 305) is a
technique for solving the equations of the linear system of equations one at a time in
sequence, and uses previously computed results as soon as they are available,
There are two important characteristics of the Gauss-Seidel method should be noted. Firstly, the
computations appear to be serial. Since each component of the new iterate depends upon all
previously computed components, the updates cannot be done simultaneously as in the Jacobi
method. Secondly, the new iterate depends upon the order in which the equations are
examined. If this ordering is changed, the components of the new iterates (and not just their
order) will also change.
where the matrices , , and represent the diagonal, strictly lower triangular, and strictly
upper triangular parts of , respectively.
in the form
where:
and
We must decompose into the sum of a lower triangular component and a strict upper
triangular component :
and
Now we have and and we can use them to obtain the vectors iteratively.
First of all, we have to choose : we can only guess. The better the guess, the quicker the
algorithm will perform.
We suppose:
We can then calculate:
(1)
where is the matrix of coefficients, is the column vector of variables, and is the column
vector of solutions.
(2)
If , then the solution is simply . If has no matrix inverse, then the solution set is the
translate of a subspace of dimension less than or the empty set.
If two equations are multiples of each other, solutions are of the form
(3)
for a real number. More generally, if , then the system is underdetermined. In this case,
elementary row and column operations can be used to solve the system as far as possible, then
the first components can be solved in terms of the last components to find the solution
space.
UUnit-3
for Note that if the given data has errors, it will also be reflected in the
polynomial so obtained.
In the following, we shall use forward and backward differences to obtain polynomial function
approximating when the tabular points 's are equally spaced. Let
(11.4.1
)
So, For or
equivalently
Thus, Now, using mathematical induction, we get
Thus,
As this uses the forward differences, it is called NEWTON'S FORWARD DIFFERENCE FORMULA for
interpolation, or simply, forward interpolation formula.
and
and in general,
For the sake of numerical calculations, we give below a convenient form of the forward
interpolation formula.
Let then
With this transformation the above forward interpolation formula is simplified to the following form:
(11.4.2
)
(11.4.3)
(11.4.4)
and so on.
coincides with on the given interval. Otherwise, this gives only an approximation to
is estimated by
Thus, using backward differences and the transformation we obtain the Newton's
backward interpolation formula as follows:
(11.4.5)
EXERCISE 11.4.2 Derive the Newton's backward interpolation formula (11.4.5) for
Remark 11.4.3 If the interpolating point lies closer to the beginning of the interval then one uses the
Newton's forward formula and if it lies towards the end of the interval then Newton's backward formula
is used.
Remark 11.4.4 For a given set of n tabular points, in general, all the n points need not be used for
interpolating polynomial. In fact N is so chosen that forward/backward difference almost remains
constant. Thus N is less than or equal to n.
EXAMPLE 11.4.5
1. Obtain the Newton's forward interpolating polynomial, for the following tabular data
and interpolate the value of the function at
2.
Solution: For this data, we have the Forward difference difference table
.005 1.1285
4.
Thus,
5.
6. Using the following table for approximate its value at Also, find an error estimate
(Note ).
7. Solution: As the point lies towards the initial tabular values, we shall use Newton's
Forward formula. The forward difference table is:
0.78 0.98926
8. In the above table, we note that is almost constant, so we shall attempt degree
polynomial interpolation.
10.
11.
12.
An error estimate for the approximate value is
13.
14. Note that exact value of (upto decimal place) is and the approximate
value, obtained using the Newton's interpolating polynomial is very close to this value. This is
also reflected by the error estimate given above.
15. Apply degree interpolation polynomial for the set of values given in Example 11.2.15, to
Therefore,
2.
to be a better approximation.
This gives,
This formula is used for interpolating the values of y near end of table.
Now note that the points and are equidistant and the divided difference are
independent of the order of their arguments. Thus, we have
where for Now using the above relations and the transformation
we get
(12.4.1)
Now taking the average of the two interpoating polynomials (12.4.1) and (12.4.2) (called GAUSS'S FIRST
AND SECOND INTERPOLATING FORMULAS, respectively), we obtain Sterling's Formula of interpolation:
(12.4.3)
These are very helpful when, the point of interpolation lies near the middle of the interpolating interval.
In this case one usually writes the diagonal form of the difference table.
EXAMPLE 12.4.1 Using the following data, find by Sterling's formula, the value of at
Here the point lies near the central tabular point Thus , we define
an
d etc.).
As we have seen, the interpolating polynomial is unique. However, there are forms other than the
Lagrange form which are more useful in some cases. We start by writing our interpolating
polynomial in the form
The advantage of this procedure over the Lagrange method is that we can increase the degree of p from
Because of the uniqueness of the interpolating polynomial, we can equate the coefficient of xn in
the two forms to obtain
This is true whatever the degree n of the interpolating polynomial, and so gives an expression for
the coefficients in the Newton formula of any degree. This shows that an depends only on
which motivates the following notation:
which is called the nth divided difference of f. We note that this is independent of the order of the
points.
Neither of the above forms is very convenient for evaluating divided differences, so we derive an
alternative and more practical form. Since the order of points does not matter, we can write down
the same interpolating polynomial with the order of the points reversed:
Now equate the coefficients of xn and xn-1 in this and the previous form to obtain
This formula is true for any value of n since the divided differences are the same for any degree of
interpolating polynomal.
The divided differences are conveniently evaluated within a table, shown in symblolic form in
Table . Notice that the table is arranged so that the function values required at each stage are
adjacent.
Table: Divided Difference Table
Table shows a numerical example; the table would normally look more compact because
the column headings would be omitted. Using the numbers in the table, we find the interpolating
polynomial of degree 4 as
It has actually turned out to be a cubic, since the given data was actually obtained from a cubic.
Suppose that we now wanted to add an extra point f(0)=-13; rather than insert this point in its
place between x=-1 and x=1, we simply add it onto the end of the table, calling it x5. We find
, , ,
Numerical Differentiation
Numerical differentiation is the process of finding the numerical value of a derivative of a given
function at a given point. In general, numerical differentiation is more difficult than numerical
integration. This is because while numerical integration requires only good continuity properties
of the function being integrated, numerical differentiation requires more complicated properties
such as Lipschitz classes. Numerical differentiation is implemented as ND[f, x, x0, Scale ->
scale] in the Mathematica package NumericalCalculus` .
There are many applications where derivatives need to be computed numerically. The simplest
approach simply uses the definition of the derivative
There are two main reasons for you to need to do numerical integration: analytical integration may be impossible or
infeasible, or you may wish to integrate tabulated data rather than known functions. In this section we outline the
main approaches to numerical integration. Which is preferable depends in part on the results required, and in part on
the function or data to be integrated.
Manual method
If you were to perform the integration by hand, one approach is to superimpose a grid on a graph of the function to
be integrated, and simply count the squares, counting only those covered by 50% or more of the function. Provided
the grid is sufficiently fine, a reasonably accurate estimate may be obtained. Figure 11 demonstrates how this may
be achieved.
Trapezium rule
(46)
The approximation represented by 1/2[f(x0) + f(x0+x)]x is called the Trapezium Rule based on its geometric
interpretation.
As we can see from equation ( 46 ), the error in the Trapezium Rule is proportional to x3. Thus, if we were to halve
x, the error would be decreased by a factor of eight. However, the size of the domain would be halved, thus
requiring the Trapezium Rule to be evaluated twice and the contributions summed. The net result is the error
decreasing by a factor of four rather than eight. The Trapezium Rule used in this manner is sometimes termed the
Compound Trapezium Rule, but more often simply the Trapezium Rule. In general it consists of the sum of
integrations over a smaller distance x to obtain a smaller error.
Suppose we need to integrate from x0 to x1. We shall subdivide this interval into n steps of size x=(x1-x0)/n
The Compound Trapezium Rule approximation to the integral is therefore
(47)
While the error for each step is O(x3), the cumulative error is n times this or O(x2) ~ O(n2).
The above analysis assumes x is constant over the interval being integrated. This is not necessary and an extension
to this procedure to utilise a smaller step size xi in regions of high curvature would reduce the total error in the
calculation, although it would remain O(x2). We would choose to reduce x in the regions of high curvature as we
can see from equation ( 46 ) that the leading order truncation error is scaled by f".
A variant on the Trapezium Rule is obtained by integrating the Taylor Series from x0x/2 to x0+x/2:
(48)
.
By evaluating the function f(x) at the midpoint of each interval the error may be slightly reduced relative to the
Trapezium rule (the coefficient in front of the curvature term is 1/24 for the Mid-point Rule compared with 1/12 for
the Trapezium Rule) but the method remains of the same order. Figure 14 provides a graphical interpretation of this
approach.
Again we may reduce the error when integrating the interval x0 to x1 by subdividing it into n smaller steps. This
Compound Mid-point Rule is then
(49)
,
with the graphical interpretation shown in figure 15 . The difference between the Trapezium
Rule and Mid-point Rule is greatly diminished in their compound forms. Comparison of
equations ( 47 ) and ( 49 ) show the only difference is in the phase relationship between the
points used and the domain, plus how the first and last intervals are calculated.
There are two further advantages of the Mid-point Rule over the Trapezium Rule. The first is
that is requires one fewer function evaluations for a given number of subintervals, and the second
that it can be used more effectively for determining the integral near an integrable singularity.
Simpson's rule
An alternative approach to decreasing the step size x for the integration is to increase the accuracy of the functions
used to approximate the integrand. Integrating the Taylor series over an interval 2x shows
(50)
Whereas the error in the Trapezium rule was O(x3), Simpson's rule is two orders more accurate at O(x5),
giving exact integration of cubics.
To improve the accuracy when integrating over larger intervals, the interval x0 to x1 may again be subdivided into n
steps. The three-point evaluation for each subinterval requires that there are an even number of subintervals. Hence
we must be able to express the number of intervals as n=2m. The Compound Simpson's rule is then
(51)
Quadratic triangulation*
Simpson's Rule may be employed in a manual way to determine the integral with nothing more than a ruler. The
approach is to cover the domain to be integrated with a triangle or trapezium (whichever is geometrically more
appropriate) as is shown in figure 17 . The integrand may cross the side of the trapezium (triangle) connecting the
end points. For each arc-like region so created (there are two in figure 17 ) the maximum deviation (indicated by
arrows in figure 17 ) from the line should be measured, as should the length of the chord joining the points of
crossing. From Simpson's rule we may approximate the area between each of these arcs and the chord as
2
area = /3 chord maxDeviation, (52)
remembering that some increase the area while others decrease it relative to the initial
trapezoidal (triangular) estimate. The overall estimate (ignoring linear measurement errors) will
be O(l5), where l is the length of the (longest) chord.
Newton-Cotes Integration
The Newton-Cotes formulas, the most commonly used numerical integration methods,
approximate the integration of a complicated function by replacing the function with many
polynomials across the integration interval. The integration of the original function can then be
obtained by summing up all polynomials whose "areas" are calculated by the weighting
coefficients and the values of the function at the nodal points.
Trapezoidal Rule:
Simpson's Rule:
A brief explanation: From any point on a curve, you can find an approximation of a nearby point
on the curve by moving a short distance along a line tangent to the curve.
Rigorous development: Starting with the differential equation (1), we replace the derivative y' by
the finite difference approximation
This formula is usually applied in the following way. We choose a step size h, and we construct
the sequence t0, t1 = t0 + h, t2 = t0 + 2h, … We denote by yn a numerical estimate of the exact
solution y(tn). Motivated by (3), we compute these estimates by the following recursive scheme
This is the Euler method (or forward Euler method, in contrast with the backward Euler method,
to be described below). The method is named after Leonhard Euler who described it in 1768.
The Euler method is an example of an explicit method. This means that the new value yn+1 is
defined in terms of things that are already known, like yn.
The backward Euler method is an implicit method, meaning that we have to solve an equation to
find yn+1. One often uses fixed point iteration or (some modification of) the Newton–Raphson
method to achieve this. Of course, it costs time to solve this equation; this cost must be taken into
consideration when one selects the method to use. The advantage of implicit methods such as (6)
is that they are usually more stable for solving a stiff equation, meaning that a larger step size h
can be used.
This method is commonly employed in neural simulations and it is the default integrator in the
GENESIS neural simulator.[1]
Generalizations
The Euler method is often not accurate enough. In more precise terms, it only has order one (the
concept of order is explained below). This caused mathematicians to look for higher-order
methods.
One possibility is to use not only the previously computed value yn to determine yn+1, but to make
the solution depend on more past values. This yields a so-called multistep method. Perhaps the
simplest is the Leapfrog method which is second order and (roughly speaking) relies on two time
values.
Almost all practical multistep methods fall within the family of linear multistep methods, which
have the form
Another possibility is to use more points in the interval [tn,tn+1]. This leads to the family of
Runge–Kutta methods, named after Carl Runge and Martin Kutta. One of their fourth-order
methods is especially popular.
Advanced features
A good implementation of one of these methods for solving an ODE entails more than the time-
stepping formula.
It is often inefficient to use the same step size all the time, so variable step-size methods have
been developed. Usually, the step size is chosen such that the (local) error per step is below some
tolerance level. This means that the methods must also compute an error indicator, an estimate
of the local error.
An extension of this idea is to choose dynamically between different methods of different orders
(this is called a variable order method). Methods based on Richardson extrapolation, such as the
Bulirsch–Stoer algorithm, are often used to construct various methods of different orders.
dense output: cheap numerical approximations for the whole integration interval, and not only
at the points t0, t1, t2, ...
event location: finding the times where, say, a particular function vanishes. This typically
requires the use of a root-finding algorithm.
support for parallel computing.
when used for integrating with respect to time, time reversibility
Alternative methods
Many methods do not fall within the framework discussed here. Some classes of alternative
methods are:
multiderivative methods, which use not only the function f but also its derivatives. This class
includes Hermite–Obreschkoff methods and Fehlberg methods, as well as methods like the
Parker–Sochacki method or Bychkov-Scherbakov method, which compute the coefficients of the
Taylor series of the solution y recursively.
methods for second order ODEs. We said that all higher-order ODEs can be transformed to first-
order ODEs of the form (1). While this is certainly true, it may not be the best way to proceed. In
particular, Nyström methods work directly with second-order equations.
geometric integration methods are especially designed for special classes of ODEs (e.g.,
symplectic integrators for the solution of Hamiltonian equations). They take care that the
numerical solution respects the underlying structure or geometry of these classes.
Analysis
Numerical analysis is not only the design of numerical methods, but also their analysis. Three
central concepts in this analysis are:
Convergence
A numerical method is said to be convergent if the numerical solution approaches the exact
solution as the step size h goes to 0. More precisely, we require that for every ODE (1) with a
Lipschitz function f and every t* > 0,
All the methods mentioned above are convergent. In fact, a numerical scheme has to be
convergent to be of any use.
For more details on this topic, see Truncation error (numerical integration).
The local (truncation) error of the method is the error committed by one step of the method.
That is, it is the difference between the result given by the method, assuming that no error was
made in earlier steps, and the exact solution:
A related concept is the global (truncation) error, the error sustained in all the steps one needs to
reach a fixed time t. Explicitly, the global error at time t is yN − y(t) where N = (t−t0)/h. The
global error of a pth order one-step method is O(hp); in particular, such a method is convergent.
This statement is not necessarily true for multi-step methods.
In the last lab you learned to use Heuns's Method to generate a numerical solution to an initial
value problem of the form:
y′ = f(x, y)
y(xo) = yo
We discussed the fact that Heun's Method was an improvement over the rather simple Euler
Method, and that though it uses Euler's method as a basis, it goes beyond it, attempting to
compensate for the Euler Method's failure to take the curvature of the solution curve into
account. Heun's Method is one of the simplest of a class of methods called predictor-corrector
algorithms. In this lab we will address one of the most powerful predictor-corrector algorithms
of all—one which is so accurate, that most computer packages designed to find numerical
solutions for differential equations will use it by default—the fourth order Runge-Kutta
Method. (For simplicity of language we will refer to the method as simply the Runge-Kutta
Method in this lab, but you should be aware that Runge-Kutta methods are actually a general
class of algorithms, the fourth order method being the most popular.)
The Runge-Kutta algorithm may be very crudely described as "Heun's Method on steroids." It
takes to extremes the idea of correcting the predicted value of the next solution point in the
numerical solution. (It should be noted here that the actual, formal derivation of the Runge-Kutta
Method will not be covered in this course. The calculations involved are complicated, and
rightly belong in a more advanced course in differential equations, or numerical methods.)
Without further ado, using the same notation as in the previous two labs, here is a summary of
the method:
xn+1 = xn + h
where
k1 = h f(xn, yn)
k4 = h f(xn + h, yn + k3)
Even though we do not plan on deriving these formulas formally, it is valuable to understand the
geometric reasoning that supports them. Let's briefly discuss the components in the algorithm
above.
First we note that, just as with the previous two methods, the Runge-Kutta method iterates the x-
values by simply adding a fixed step-size of h at each iteration.
The y-iteration formula is far more interesting. It is a weighted average of four values—k1, k2, k3,
and k4. Visualize distributing the factor of 1/6 from the front of the sum. Doing this we see that
k1 and k4 are given a weight of 1/6 in the weighted average, whereas k2 and k3 are weighted 1/3,
or twice as heavily as k1 and k4. (As usual with a weighted average, the sum of the weights 1/6,
1/3, 1/3 and 1/6 is 1.) So what are these ki values that are being used in the weighted average?
k1 you may recognize, as we've used this same quantity on both of the previous labs. This
quantity, h f(xn, yn), is simply Euler's prediction for what we've previously called Δy—the
vertical jump from the current point to the next Euler-predicted point along the numerical
solution.
k2 we have never seen before. Notice the x-value at which it is evaluating the function f. xn + h/2
lies halfway across the prediction interval. What about the y-value that is coupled with it?
yn + k1/2 is the current y-value plus half of the Euler-predicted Δy that we just discussed as being
the meaning of k1. So this too is a halfway value, this time vertically halfway up from the current
point to the Euler-predicted next point. To summarize, then, the function f is being evaluated at a
point that lies halfway between the current point and the Euler-predicted next point. Recalling
that the function f gives us the slope of the solution curve, we can see that evaluating it at the
halfway point just described, i.e. f(xn + h/2, yn + k1/2), gives us an estimate of the slope of the
solution curve at this halfway point. Multiplying this slope by h, just as with the Euler Method
before, produces a prediction of the y-jump made by the actual solution across the whole width
of the interval, only this time the predicted jump is not based on the slope of the solution at the
left end of the interval, but on the estimated slope halfway to the Euler-predicted next point.
Whew! Maybe that could use a second reading for it to sink in!
k3 has a formula which is quite similar to that of k2, except that where k1 used to be, there is now
a k2. Essentially, the f-value here is yet another estimate of the slope of the solution at the
"midpoint" of the prediction interval. This time, however, the y-value of the midpoint is not
based on Euler's prediction, but on the y-jump predicted already with k2. Once again, this slope-
estimate is multiplied by h, giving us yet another estimate of the y-jump made by the actual
solution across the whole width of the interval.
k4 evaluates f at xn + h, which is at the extreme right of the prediction interval. The y-value
coupled with this, yn + k3, is an estimate of the y-value at the right end of the interval, based on
the y-jump just predicted by k3. The f-value thus found is once again multiplied by h, just as with
the three previous ki, giving us a final estimate of the y-jump made by the actual solution across
the whole width of the interval.
In summary, then, each of the ki gives us an estimate of the size of the y-jump made by the actual
solution across the whole width of the interval. The first one uses Euler's Method, the next two
use estimates of the slope of the solution at the midpoint, and the last one uses an estimate of the
slope at the right end-point. Each ki uses the earlier ki as a basis for its prediction of the y-jump.
is simply the y-value of the current point plus a weighted average of four different y-jump
estimates for the interval, with the estimates based on the slope at the midpoint being weighted
twice as heavily as the those using the slope at the end-points.
As we have just seen, the Runge-Kutta algorithm is a little hard to follow even when one only
considers it from a geometric point of view. In reality the formula was not originally derived in
this fashion, but with a purely analytical approach. After all, among other things, our geometric
"explanation" doesn't even account for the weights that were used. If you're feeling ambitious, a
little research through a decent mathematics library should yield a detailed analysis of the
derivation of the method.
One member of the family of Runge–Kutta methods is so commonly used that it is often referred
to as "RK4", "classical Runge–Kutta method" or simply as "the Runge–Kutta method".
The RK4 method for this problem is given by the following equations:
[1]
(Note: the above equations have different but equivalent definitions in different texts).[2]
Thus, the next value ( ) is determined by the present value ( ) plus the weighted average
of four increments, where each increment is the product of the size of the interval, h, and an
estimated slope specified by function f on the right-hand side of the differential equation.
is the increment based on the slope at the beginning of the interval, using , (Euler's
method) ;
is the increment based on the slope at the midpoint of the interval, using ;
is again the increment based on the slope at the midpoint, but now using ;
is the increment based on the slope at the end of the interval, using .
In averaging the four increments, greater weight is given to the increments at the midpoint. The
weights are chosen such that if is independent of , so that the differential equation is
equivalent to a simple integral, then RK4 is Simpson's rule.[3]
The RK4 method is a fourth-order method, meaning that the error per step is on the order of ,
while the total accumulated error has order .
The family of explicit Runge–Kutta methods is a generalization of the RK4 method mentioned
above. It is given by
where
[4]
(Note: the above equations have different but equivalent definitions in different texts).[2]
To specify a particular method, one needs to provide the integer s (the number of stages), and the
coefficients aij (for 1 ≤ j < i ≤ s), bi (for i = 1, 2, ..., s) and ci (for i = 2, 3, ..., s). The matrix [aij] is
called the Runge–Kutta matrix, while the bi and ci are known as the weights and the nodes.[5]
These data are usually arranged in a mnemonic device, known as a Butcher tableau (after John
C. Butcher):
There are also accompanying requirements if we require the method to have a certain order p,
meaning that the local truncation error is O(hp+1). These can be derived from the definition of the
truncation error itself. For example, a 2-stage method has order 2 if b1 + b2 = 1, b2c2 = 1/2, and
a21 = c2.[6]
Examples
1/
1/2
2
1/
1/2 0
2
1 0 0 1
However, the simplest Runge–Kutta method is the (forward) Euler method, given by the formula
. This is the only consistent explicit Runge–Kutta method with one
stage. The corresponding tableau is:
An example of a second-order method with two stages is provided by the midpoint method
1/2 1/2
0 1
The midpoint method is not the only second-order Runge–Kutta method with two stages. In fact,
there is a family of such methods, parameterized by α, and given by the formula
[8]
Usage
2/3 2/3
1/4 3/4
with step size h = 0.025, so the method needs to take four steps.
The adaptive methods are designed to produce an estimate of the local truncation error of a
single Runge–Kutta step. This is done by having two methods in the tableau, one with order
and one with order .
where the are the same as for the higher order method. Then the error is
which is . The Butcher tableau for this kind of method is extended to give the values of
:
The Runge–Kutta–Fehlberg method has two methods of orders 5 and 4. Its extended Butcher
tableau is:
1/4 1/4
However, the simplest adaptive Runge–Kutta method involves combining the Heun method,
which is order 2, with the Euler method, which is order 1. Its extended Butcher tableau is:
11
1/2 1/2
1 0
Other adaptive Runge–Kutta methods are the Bogacki–Shampine method (orders 3 and 2), the
Cash–Karp method and the Dormand–Prince method (both with orders 5 and 4).
All Runge–Kutta methods mentioned up to now are explicit methods. Unfortunately, explicit
Runge–Kutta methods are generally unsuitable for the solution of stiff equations because their
region of absolute stability is small; in particular, it is bounded.[9] This issue is especially
important in the solution of partial differential equations.
The instability of explicit Runge–Kutta methods motivates the development of implicit methods.
An implicit Runge–Kutta method has the form
where
[10]
The difference with an explicit method is that in an explicit method, the sum over j only goes up
to i − 1. This also shows up in the Butcher tableau. For an implicit method, the coefficient matrix
is not necessarily lower triangular:[7]
The consequence of this difference is that at every step, a system of algebraic equations has to be
solved. This increases the computational cost considerably. If a method with s stages is used to
solve a differential equation with m components, then the system of algebraic equations has ms
components. In contrast, an implicit s-step linear multistep method needs to solve a system of
algebraic equations with only s components.[11]
Examples
The simplest example of an implicit Runge–Kutta method is the backward Euler method:
which can be re-arranged to get the formula for the backward Euler method listed above.
Another example for an implicit Runge–Kutta method is the trapezoidal rule. Its Butcher tableau
is:
The trapezoidal rule is a collocation method (as discussed in that article). All collocation
methods are implicit Runge–Kutta methods, but not all implicit Runge–Kutta methods are
collocation methods.[12]
The Gauss–Legendre methods form a family of collocation methods based on Gauss quadrature.
A Gauss–Legendre method with s stages has order 2s (thus, methods with arbitrarily high order
can be constructed).[13] The method with two stages (and thus order four) has Butcher tableau:
[11]
Stability
The advantage of implicit Runge–Kutta methods above explicit ones is their greater stability,
especially when applied to stiff equations. Consider the linear test equation y' = λy. A Runge–
Kutta method applied to this equation reduces to the iteration , with r given
by
[14]
where e stands for the vector of ones. The function r is called the stability function.[15] It follows
from the formula that r is the quotient of two polynomials of degree s if the method has s stages.
Explicit methods have a strictly lower triangular matrix A, which implies that det(I − zA) = 1 and
that the stability function is a polynomial.[16]
The numerical solution to the linear test equation decays to zero if | r(z) | < 1 with z = hλ. The set
of such z is called the domain of absolute stability. In particular, the method is said to be A-stable
if all z with Re(z) < 0 are in the domain of absolute stability. The stability function of an explicit
Runge–Kutta method is a polynomial, so explicit Runge–Kutta methods can never be A-
stable.[16]
The Gauss–Legendre method with s stages has order 2s, so its stability function is the Padé
approximant with m = n = s. It follows that the method is A-stable.[18] This shows that A-stable
Runge–Kutta can have arbitrarily high order. In contrast, the order of A-stable linear multistep
methods cannot exceed two.[19]
where:
are increments obtained evaluating the derivatives of at the -th order.
We develop the derivation[20] for the Runge–Kutta fourth order method using the general formula
with evaluated, as explained above, at the starting point, the midpoint and the end point of
any interval , thus we choose:
and for the previous relations we can show that the following equalities holds up to :
where:
If we now express the general formula using what we just derived we obtain:
and comparing this with the Taylor series of around :
Predictor–corrector method
When considering the numerical solution of ordinary differential equations (ODEs), a predictor–
corrector method typically uses an explicit method for the predictor step and an implicit method
for the corrector step.
A simple predictor–corrector method can be constructed from the Euler method (an explicit
method) and the trapezoidal rule (an implicit method).
First, the predictor step: starting from the current value , calculate an initial guess value
via the Euler method,
Next, the corrector step: improve the initial guess using trapezoidal rule,
There are different variants of a predictor–corrector method, depending on how often the
corrector method is applied. The Predict–Evaluate–Correct–Evaluate (PECE) mode refers to the
variant in the above example:
It is also possible to evaluate the function f only once per step by using the method in Predict–
Evaluate–Correct (PEC) mode:
Additionally, the corrector step can be repeated in the hope that this achieves an even better
approximation to the true solution. If the corrector method is run twice, this yields the PECECE
mode:
The PECEC mode has one fewer function evaluation. More generally, if the corrector is run k
times, the method is in P(EC)k or P(EC)kE mode. If the corrector method is iterated until it
converges, this could be called PE(CE)∞
Predictor–corrector methods for solving ODEs
When considering the numerical solution of ordinary differential equations (ODEs), a predictor–
corrector method typically uses an explicit method for the predictor step and an implicit method
for the corrector step.
A simple predictor–corrector method can be constructed from the Euler method (an explicit
method) and the trapezoidal rule (an implicit method).
First, the predictor step: starting from the current value , calculate an initial guess value
via the Euler method,
Next, the corrector step: improve the initial guess using trapezoidal rule,
There are different variants of a predictor–corrector method, depending on how often the
corrector method is applied. The Predict–Evaluate–Correct–Evaluate (PECE) mode refers to the
variant in the above example:
It is also possible to evaluate the function f only once per step by using the method in Predict–
Evaluate–Correct (PEC) mode:
Additionally, the corrector step can be repeated in the hope that this achieves an even better
approximation to the true solution. If the corrector method is run twice, this yields the PECECE
mode:
The PECEC mode has one fewer function evaluation. More generally, if the corrector is run k
times, the method is in P(EC)k or P(EC)kE mode. If the corrector method is iterated until it
converges, this could be called PE(CE)∞