electronics engineering
Course handbook · Second year · Edition with space for notes
Numerical Calculus
Numerical calculus: floating-point errors, solving equations and linear systems, interpolation, numerical integration and the algorithms behind them.
- 9Topics
- 0Solved exercises
- 50Formula sheet
Free handbook generated from the lessons of the site and updated often, every time a lesson or an exercise changes: the latest version is always at www.electronics-engineering.com/handbook/number-calculation. Links work in the PDF too.
1Floating-point arithmetic, errors and conditioning
Numerical analysis studies how to solve mathematical problems (equations, systems, integrals, differential equations) on a computer when an exact formula does not exist or cannot be used. The first step is to understand what a computer calculates with: not real numbers, but a finite set of floating-point numbers. This is where rounding errors come from, along with the difference between a well-conditioned problem and a stable algorithm.
Floating-point numbers
A computer represents a real number as
![]()
with a sign, a mantissa (significand) of
binary digits and an exponent
in a limited range. The IEEE 754 standard, used by every modern processor, provides:
| Format | Total bits | Mantissa | Exponent | Decimal digits | Machine epsilon |
|---|---|---|---|---|---|
| single (float) | 32 | 23 + 1 | 8 | about 7 | |
| double | 64 | 52 + 1 | 11 | about 16 |
The leading bit of the mantissa is always 1 and is not stored (the “hidden bit”), hence the “+ 1”.

Machine epsilon
is the gap between 1 and the next representable number. Every real
in the representable range is rounded to the nearest one, with a relative error of at most
:
![]()
And every arithmetic operation has the same error:
.
Typical surprises.
cannot be represented exactly in binary (like
in decimal), so
in double precision gives
. Never compare floating-point numbers for exact equality: use
.- In single precision
: beyond
not every integer is representable. - There are special values:
(for example
) and NaN, “not a number” (for example
), which propagate through calculations instead of stopping the program.
Catastrophic cancellation
Subtracting two nearly equal numbers is the most dangerous operation. If
and
have 16 correct digits and agree in the first 12, the difference has only 4: the rest is rounding noise.
Example: the quadratic equation.
has roots of about
and
. The textbook formula for the small root,
, subtracts two nearly equal numbers and in double precision gives about
: a 25% error. The fix is to rewrite the formula: compute the large root first, with no cancellation, then the small one from
, that is
, exact.
Example:
for small
. With
, the rounded
is exactly 1 and the result is 0, while the true value is
. Rewriting
makes the calculation accurate. Libraries provide dedicated functions, such as expm1 and log1p, precisely for these cases.
Conditioning of a problem
Conditioning measures how much the exact result of a problem changes when the data are slightly perturbed. For a function
, the relative condition number is
![]()
the relative error in the result is about
times that in the data. If
is large the problem is ill-conditioned: even a perfect calculation on rounded data gives unreliable results. It is a property of the problem, not of the algorithm.
For linear systems
the condition number is
. If
, about
significant digits are lost: with
in double precision only 4 reliable digits remain. The Hilbert matrix
of order 10 has
: the classic example of a system that is almost impossible to solve on a computer although it is invertible.
Stability of an algorithm
An algorithm is stable if it does not amplify rounding errors more than the problem itself already does. The same well-conditioned problem can be solved with a stable or an unstable algorithm, as in the quadratic equation example.
An unstable algorithm. The integrals
satisfy
, with
. Running the recurrence forwards, the initial error (of the order of
) is multiplied by
: with
,
, and the result is completely wrong, even negative, although
always lies between 0 and 1. Running it backwards,
, starting from any value at a large
, the error is divided by
at each step and the result is accurate.
A rule of thumb
Final error
condition number
machine epsilon, if the algorithm is stable. In the following lessons, for each method we will ask three questions: does it converge, how fast, and is it stable. The famous case of the Ariane 5 rocket, which exploded in 1996 because a 64-bit floating-point number was converted into a 16-bit integer that could not hold it, is a reminder that these details are not academic.
2Root finding for nonlinear equations
Finding where a function is zero is one of the most frequent problems: the operating point of a diode in a circuit (where the diode’s exponential equation meets the load line), the frequency at which a filter attenuates by 3 dB, the launch angle to hit a target. For almost every nonlinear equation there is no formula, so one proceeds by iteration: start from an estimate and improve it until it is accurate enough.
The bisection method
If
is continuous on
and
and
have opposite signs, by the intermediate value theorem of Analysis 1 there is at least one root. Bisection halves the interval at each step:
- compute the midpoint
; - if
and
have opposite signs the root is in
, otherwise in
; - repeat until the interval is smaller than the tolerance.
After
steps the interval is
wide. Going from an interval of 1 to a tolerance of
takes 20 steps (
). The method is slow but it always converges, and the error bound is guaranteed. It gains one decimal digit every 3.3 steps or so.
Newton’s method
The idea is to replace the function with its tangent line and take as the new estimate the point where the tangent crosses the axis:
![]()

, the tangent to the graph at
crosses the axis at
; the tangent at
gives
, and so on. The estimates approach the root α very quickly.Example: the square root. With
the formula becomes
, the Babylonian method. For
starting from
(as in the figure): 1.8333; 1.4621; 1.41500; 1.4142138; 1.41421356237311. The correct decimal digits go 0, 1, 3, 6, 13: they roughly double at every step.
Proof of quadratic convergence
Let
be the root and
the error. Expanding
with Taylor around
, evaluated at
:
![]()
Dividing by
and using the definition of the iteration,
:
![]()
The new error is proportional to the square of the old one: if
,
is of the order of
. This is quadratic convergence, far faster than bisection, which is linear.
Newton’s limits
- It needs the derivative, which is not always available.
- Convergence is guaranteed only when starting close enough to the root. Far away, the tangents can send the estimate anywhere or make it oscillate: with
and
the estimates diverge. - If
(a double root) convergence becomes only linear.
In practice the two methods are combined: bisection until the interval is small, then Newton to finish in a few steps. This is what functions such as MATLAB’s fzero or SciPy’s brentq do.
The secant method
When the derivative is not available it is approximated by the difference quotient of the last two estimates:
![]()
Convergence is superlinear, of order
(the golden ratio), and each step needs only one evaluation of
: it is often more efficient than Newton.
Fixed-point iteration
Every equation
can be rewritten as
, and a fixed point sought with
. It converges if
near the solution: the error is multiplied by about
at each step.
Example.
: starting from any value and repeatedly pressing the cosine key of a calculator (in radians) you reach 0.739085…, because
near the solution. Newton itself is a fixed-point iteration with
, which has
: that is why it converges faster.
Nonlinear systems
For a system
of
equations in
unknowns, Newton generalises with the Jacobian matrix of Analysis 2:
![]()
at each step a linear system is solved. It is the heart of SPICE: for a circuit with diodes and transistors, the simulator linearises the components around the current estimate and solves the linear system, repeating until the voltages stop changing. When a simulation “fails to converge”, it is Newton failing to find the solution from the initial guess.
Stopping criteria
Stop when the difference between two successive estimates is below a tolerance,
, or when the residual
is small enough, and in any case after a maximum number of iterations, so as not to get stuck if the method does not converge. A small residual alone is not enough: if the function is very flat near the root,
can be tiny even far from the solution.
3Numerical linear algebra: direct and iterative methods
In Geometry and Algebra linear systems were solved with Gaussian elimination on 3×3 matrices. In real problems matrices have thousands or millions of rows: simulating an integrated circuit, finite element structural analysis, reconstructing an image in a CT scan. What matters here is the cost of the computation, stability with respect to rounding and the structure of the matrix. We look at direct methods (LU and Cholesky factorisations) and iterative ones (Jacobi and Gauss-Seidel).
LU factorisation
Gaussian elimination, recording the multipliers used, splits the matrix into the product
![]()
with
lower triangular (1s on the diagonal and the multipliers below) and
upper triangular (the echelon form). The system
becomes two triangular systems, solved by substitution:
![]()
The advantage. The factorisation costs about
operations, but the two substitutions only
. If many systems with the same matrix and different right-hand sides must be solved (as in a simulator where only the sources change at each step), you factorise once. With
:
operations for the factorisation,
for each new right-hand side.
Example.
![Rendered by QuickLaTeX.com \[ A = \begin{pmatrix} 2 & 1 & 1\\ 4 & 3 & 3\\ 8 & 7 & 9\end{pmatrix} = \begin{pmatrix} 1 & 0 & 0\\ 2 & 1 & 0\\ 4 & 3 & 1\end{pmatrix}\begin{pmatrix} 2 & 1 & 1\\ 0 & 1 & 1\\ 0 & 0 & 2\end{pmatrix} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-84742d209aa5acdd0a8e0d47ed364837_l3.png)
The multipliers 2 and 4 eliminate the first column, the 3 the second.
Pivoting
If a zero appears on the diagonal during elimination the method stops; if a very small number appears, you divide by it and rounding errors blow up.
Example. With
and
, the true solution is about
. Without swaps the multiplier is
, and in double precision the second row becomes
because
rounds to
: you get
and then
, completely wrong. Swapping the rows before eliminating gives the correct result.
Partial pivoting chooses at each step, as pivot, the entry of largest magnitude in the column, and swaps rows. The multipliers then have magnitude at most 1 and the method is stable in practice. The factorisation becomes
, with
a permutation matrix. It is the standard method of every numerical library (LAPACK, NumPy, MATLAB).
Symmetric positive definite matrices: Cholesky
If
is symmetric and positive definite (like structural stiffness matrices, covariance matrices, nodal matrices of resistor-only circuits), then
![]()
with
lower triangular. The Cholesky factorisation costs half as much as LU (
), needs no pivoting and is always stable. If the square root of a negative number appears during the calculation, the matrix was not positive definite: it is also the fastest way to check.
Sparse matrices
In applications, large matrices are almost all zeros: in a circuit’s nodal matrix, each row has non-zero entries only for directly connected nodes. A full
matrix would take 8 terabytes in double precision; sparse, with 10 entries per row, 80 megabytes. Sparse direct methods reorder rows and columns to limit fill-in, the zeros that become non-zero during elimination. This is what SPICE and finite element programs do.
Iterative methods
For huge sparse matrices it is often better to start from an estimate
and improve it, without ever factorising.
Jacobi. From equation
solve for
using the previous iteration’s values for the other unknowns:
![Rendered by QuickLaTeX.com \[ x_i^{(k+1)} = \frac{1}{a_{ii}}\Big(b_i - \sum_{j \ne i}a_{ij}\,x_j^{(k)}\Big) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-91cf97e1c756c2230a8e90e218f6596d_l3.png)
Gauss-Seidel. Like Jacobi, but it uses the values already updated in the same iteration straight away. It usually converges about twice as fast and uses less memory.
Example.
,
(solution
,
). Gauss-Seidel from
:
,
; then
,
; then
,
. Three steps, three correct digits.
When they converge
Writing the iteration as
, the error is multiplied by
at each step, so the method converges if and only if the spectral radius of
(the largest magnitude of its eigenvalues, Geometry and Algebra lesson) is less than 1. A sufficient condition that is easy to check: the matrix is diagonally dominant,
for every row. The nodal matrices of resistive circuits almost always are.
For the largest problems more sophisticated iterative methods are used, such as the conjugate gradient method for symmetric positive definite matrices, which in exact arithmetic reaches the solution in at most
steps and in practice needs far fewer, especially with a good preconditioner.

The residual is not enough
After computing
, the residual
is easy to compute, but a small residual does not guarantee an accurate solution. The relative error is bounded by
![]()
with
the condition number of the lesson on errors. If
is large, even a tiny residual can hide a large error.
4Interpolation and splines
Often a function is known only at certain points: the values in a table, the measurements of an experiment, the samples of a signal, the characteristic curve of a sensor supplied by the manufacturer. Interpolating means building a simple function that passes exactly through those points, to estimate the values in between. In this lesson we look at the interpolating polynomial, Runge’s phenomenon which shows its limits, Chebyshev nodes and splines.
The interpolating polynomial
Given
points
with distinct abscissas, there is exactly one polynomial of degree at most
through all of them.
Proof of uniqueness. If two polynomials
and
of degree at most
pass through the same
points, the difference
has degree at most
and vanishes at
distinct points. A non-zero polynomial of degree
has at most
roots, so
.
The Lagrange form. Build the basis polynomials
![Rendered by QuickLaTeX.com \[ \ell_i(x) = \prod_{j \ne i}\frac{x - x_j}{x_i - x_j} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-8023c75bdf21158b90c262f216457303_l3.png)
which equal 1 at
and 0 at every other node. Then
![Rendered by QuickLaTeX.com \[ p_n(x) = \sum_{i=0}^{n}y_i\,\ell_i(x) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-9122bfaf5654256c569edce72232a445_l3.png)
passes through all the points. Example: for
,
,
one gets
. The Lagrange form is elegant for proofs; for calculations the Newton form with divided differences is used, which lets you add a point without recomputing everything.
The interpolation error
If
has
continuous derivatives, for every
there is
in the interval such that
![Rendered by QuickLaTeX.com \[ f(x) - p_n(x) = \frac{f^{(n+1)}(\xi)}{(n + 1)!}\,\prod_{i=0}^{n}(x - x_i) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-03950ea35a952bde177b8ff58b528f68_l3.png)
The error depends on two factors: how “smooth” the function is (the high-order derivative) and how the nodes are spread (the product).
Runge’s phenomenon
It seems natural that more points always give a better interpolation. They do not. In 1901 Runge studied the function
![]()
perfectly smooth, and interpolated it at equally spaced nodes.

With equally spaced nodes, as the degree rises the error near the ends grows without limit: with 21 nodes the polynomial reaches values above 50, while the function stays between 0 and 1. The cause is the product
, which with equally spaced nodes is much larger near the ends than in the middle. (The deep reason is complex, in the sense of complex numbers:
has poles at
, close to the interval.)
The practical lesson: do not use high-degree polynomials on equally spaced nodes. It is the same reason a degree-10 polynomial fit to experimental data produces curves with absurd wiggles between the points.
Chebyshev nodes
If the nodes can be chosen, it pays to cluster them towards the ends. The Chebyshev nodes on
are
![]()
the projections onto the axis of equally spaced points on a semicircle. They make the product
as small as possible (at most
), and with them the interpolation of smooth functions always converges. It is the principle numerical libraries use to approximate mathematical functions.
Splines
The most used alternative in practice is to interpolate piecewise: a low-degree polynomial between each pair of nodes, joined smoothly.
- Piecewise linear: the points are joined with segments. Simple and free of oscillations, but with corners. It is what a spreadsheet does with a line chart, and a lookup table in a microcontroller.
- Cubic spline: between two nodes a third-degree polynomial, with values, first derivatives and second derivatives continuous at the nodes. It is the “smoothest” curve through the points: it minimises the integral of the squared second derivative, that is the bending energy of an elastic strip forced through the points. This is exactly where the name comes from: the spline was the flexible wooden strip that ship draughtsmen held with weights to draw hull curves.
The coefficients are found by solving a tridiagonal linear system, which takes
operations. Splines do not suffer from Runge’s phenomenon, and with spacing
the error is proportional to
.
Applications. Font outlines (TrueType uses quadratic Bézier curves, PostScript and OpenType cubic ones), the paths of robots and CNC machines, linearising sensors such as thermocouples and thermistors from the manufacturer’s tables, resampling audio and images.
Interpolation and approximation
Interpolation makes sense when the data are exact. If they are noisy measurements, forcing the curve through every point means following the noise too. In that case one looks for a simple curve that passes close to the points overall: least squares approximation, the topic of the next lesson.
5Least squares approximation
Real measurements are noisy: forcing a curve through every point, as interpolation does, means following the errors too. The least squares method, invented by Gauss and Legendre in the early nineteenth century to compute planetary orbits, instead looks for the curve of a given form that passes as close as possible to all the points together. It is how sensors are calibrated, model parameters estimated and the trend line of any chart drawn.
The problem
Given
points
, we look for a function from a chosen family, for example a line
, that minimises the sum of the squared residuals:
![Rendered by QuickLaTeX.com \[ S(c_0, c_1) = \sum_{i=1}^{m}\big(y_i - c_0 - c_1x_i\big)^2 \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-9e323fb24af6902118c595adaae45057_l3.png)

(dashed red).Why squares and not absolute values? Because the function to minimise becomes smooth, the minimum is found with derivatives and leads to a linear system; and because, if the measurement errors are Gaussian, the solution is also the most likely estimate of the parameters.
The normal equations
Setting the partial derivatives to zero (Analysis 2 lesson on maxima and minima):
![]()
that is
![Rendered by QuickLaTeX.com \[ \begin{cases} m\,c_0 + \left(\sum x_i\right)c_1 = \sum y_i\\ \left(\sum x_i\right)c_0 + \left(\sum x_i^2\right)c_1 = \sum x_iy_i \end{cases} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-e65482a68fff05c518ec43678b6f3f33_l3.png)
with solution
![]()
where
and
are the means. The line always passes through the centroid of the points
.
Example: calibrating a sensor. A temperature sensor gives the voltages 0.52, 0.71, 0.88, 1.11, 1.29 V at 0, 20, 40, 60, 80 °C. The means are
°C and
V. The deviations from the means are
for the temperatures and
for the voltages, so
and
. The sensitivity is
V/°C, that is 9.7 mV/°C, and the offset
V. The model gives 0.514, 0.708, 0.902, 1.096, 1.290 V: the residuals are a few millivolts, the largest 22 mV at 40 °C.
Matrix form
The problem is written
, where
has one row per measurement and one column per parameter (for the line, the columns are all 1s and the
). It is a system with more equations than unknowns, in general with no exact solution. The least squares solution satisfies the normal equations
![]()
and, as seen in Geometry and Algebra,
is the orthogonal projection of
onto the column space of
: the residual vector is perpendicular to every column.
Numerical warning. Forming
squares the condition number: if
,
, and 12 digits are lost instead of 6. Libraries instead use the QR factorisation,
with
having orthonormal columns, which leads to the triangular system
without worsening the conditioning. For the hardest problems the singular value decomposition (SVD) is used.
Not just lines
The method works with any model that is linear in the parameters, even if nonlinear in
:
- polynomials
(of low degree, so as not to fall back into Runge’s oscillations); - combinations of known functions, such as
, to estimate the amplitude and phase of a signal of known frequency; - models that become linear after a transformation:
becomes
. This is how the time constant of an RC discharge is estimated from a series of voltage readings.
For models that are genuinely nonlinear in the parameters (for example a diode characteristic with series resistance) iterative methods such as Gauss-Newton and Levenberg-Marquardt are used, which linearise the model at each step, just as Newton does for equations.
How good is the fit
- The residuals
must show no pattern: if they form a curve, the model is wrong (for example a line fitted to quadratic data). - The coefficient of determination
gives the fraction of variability explained by the model: 1 is perfect, 0 means the model explains nothing beyond the mean. - Adding parameters always shrinks the residuals, but beyond a certain point the model follows the noise instead of the phenomenon (overfitting): with
points, a polynomial of degree
has zero residuals and is useless.
The same principle, minimising a squared error over a lot of data, underlies the training of neural networks: the “weights” are the parameters, and the gradient of the error guides their correction.
6Numerical integration
Many integrals have no antiderivative expressible with elementary functions (
,
, the perimeter of an ellipse), and often the function is known only at points, like the samples of a signal. Numerical integration (or quadrature) approximates the integral by a weighted sum of the function’s values at a few points. It is how a multimeter computes the RMS value of a voltage, how an electronic meter computes the energy used and how the area under an experimental curve is estimated.
The common idea
Split
into
intervals of width
, with nodes
, approximate
on each interval with a polynomial and integrate the polynomial exactly.

The trapezoidal rule
On each interval
is replaced by the segment between the two ends, and the area is that of a trapezium. Adding up:
![Rendered by QuickLaTeX.com \[ \int_a^b f\,dx \approx T_h = h\left[\frac{f_0}{2} + f_1 + f_2 + \dots + f_{n-1} + \frac{f_n}{2}\right] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-603d604bf7f030afc80dfe7bcd64582a_l3.png)
The error is
![Rendered by QuickLaTeX.com \[ \int_a^b f\,dx - T_h = -\frac{(b - a)\,h^2}{12}\,f''(\xi) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-a512041865175688f6028c305e6fb14e_l3.png)
proportional to
: halving the step cuts the error by four. The rule is exact for first-degree polynomials. The sign of the second derivative tells which side the error is on: for a convex function the trapezia lie above the curve and overestimate the integral.
Simpson’s rule
With
even, on each pair of intervals
is replaced by the parabola through the three points. Integrating the parabola gives the weights
, and adding up:
![Rendered by QuickLaTeX.com \[ \int_a^b f\,dx \approx S_h = \frac h3\Big[f_0 + 4f_1 + 2f_2 + 4f_3 + \dots + 2f_{n-2} + 4f_{n-1} + f_n\Big] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-3d508dae5dca6f47628562a2b4a29534_l3.png)
The error is
![]()
proportional to
: halving the step cuts the error by sixteen. Surprisingly the rule is exact for cubic polynomials too, not just parabolas: the error of the cubic term cancels by symmetry.
Example.
With
(
):
| Method | Value | Error |
|---|---|---|
| trapezoidal | 0.742984 | |
| Simpson | 0.746855 |
With the same five function values, Simpson is more than a hundred times more accurate.
Proof: Simpson from the trapezoidal rule
The trapezoidal error has the form
. Computing with steps
and
and combining to remove the
term:
![]()
and working it out gives exactly Simpson’s rule. This is Richardson extrapolation: knowing how the error behaves, you can remove it. Repeating the idea gives Romberg’s method, which reaches high accuracy with few values.
Estimating the error without the derivative
The error formulas contain unknown derivatives. In practice the result is compared at two different steps: for the trapezoidal rule,
. Adaptive integration programs do this on each subinterval, and add points only where the function changes quickly: few points where it is flat, many near a peak.
Gaussian quadrature
The trapezoidal and Simpson rules use equally spaced nodes. If the node positions can be chosen too,
points can integrate a polynomial of degree
exactly: the Gauss-Legendre formulas. With just two points at
on
:
![Rendered by QuickLaTeX.com \[ \int_{-1}^{1}f\,dx \approx f\!\left(-\tfrac{1}{\sqrt3}\right) + f\!\left(\tfrac{1}{\sqrt3}\right) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-2e263196147b29d289a6c4302591a942_l3.png)
exact for every cubic polynomial, like Simpson but with one point fewer. The nodes are the roots of the Legendre polynomials. These formulas are used in finite element programs, where every function evaluation is expensive.
Integrals of sampled signals
For a signal sampled with period
the nodes are fixed by the converter, and the trapezoidal rule or Simpson is applied to the samples. Example: the RMS value of a voltage,
![Rendered by QuickLaTeX.com \[ V_{rms} = \sqrt{\frac{1}{T_p}\int_0^{T_p}v^2(t)\,dt} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-9892e24a4805e65ee1e21d79ca70d354_l3.png)
is computed in “true RMS” multimeters by summing the squared samples over a period. For a periodic signal sampled over a whole number of periods, the trapezoidal rule is surprisingly accurate: the error falls faster than any power of
, because the end errors cancel. It is the same reason the DFT computes the Fourier coefficients of band-limited signals exactly.
Improper integrals and singularities
On infinite intervals the interval is truncated where the function is negligible, or a change of variable makes it finite. If the function has an integrable singularity, such as
at 0, formulas with nodes at the ends fail (
is infinite) and convergence is slow: it pays to remove the singularity with a change of variable (here
) before integrating.
7Numerical solution of ODEs
The differential equations you can solve with pen and paper are few: linear ones with constant coefficients, separable ones. A circuit with a diode, a pendulum with large swings, a motor with nonlinear friction, the orbit of a satellite around the oblate Earth all need numerical methods. The idea is simple: start from the initial condition and advance in small time steps, following the direction field. In this lesson we cover Euler’s and the Runge-Kutta methods, order of accuracy and the problem of stability.
The problem
![]()
where
can also be a vector: every higher-order equation can be rewritten as a first-order system. The pendulum
becomes
,
. Choose the times
, with
the step, and compute approximations
.
The explicit Euler method
Follow the tangent for one step:
![]()
It is the definition of the derivative read backwards. Each step makes a local error proportional to
(the neglected Taylor term); after
steps the global error is proportional to
. Euler is a first-order method: halving the step halves the error.

,
, the exact solution is
(blue). Euler with step
(red) and
(orange) stays below the true curve, because the tangent of a convex function lies below it; halving the step roughly halves the error.Example. With
Euler gives
, that is
. To reach
: with
,
instead of
(4.6% error); with
,
(0.5% error). It is the definition of
as the limit of
.
Runge-Kutta methods
To get more accuracy without shrinking the step too much, evaluate the slope at several points within the step and take a weighted average. Heun’s method (second-order Runge-Kutta) takes a trial Euler step, computes the slope at the end point and uses the average of the two slopes:
![]()
The most used method is fourth-order Runge-Kutta (RK4):
![Rendered by QuickLaTeX.com \[ \begin{aligned} k_1 &= f(t_n, y_n) & k_2 &= f\!\left(t_n + \tfrac h2, y_n + \tfrac h2k_1\right)\\ k_3 &= f\!\left(t_n + \tfrac h2, y_n + \tfrac h2k_2\right) & k_4 &= f(t_n + h, y_n + hk_3) \end{aligned} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-89e8f309a8a58016b73628c1a11db376_l3.png)
![]()
Four evaluations of
per step, global error proportional to
: halving the step cuts the error by sixteen. For
with
up to
, RK4 gives
against
: an error of 2 millionths, against Euler’s 4.6% with the same step. The weights
have the same structure as Simpson’s rule: for
depending only on
, RK4 is Simpson.
Adaptive step. Modern solvers (MATLAB’s ode45, SciPy’s solve_ivp) compute two estimates of different order at each step, use their difference as an error estimate and adjust the step: large where the solution is quiet, small where it changes quickly.
Stability and stiff problems
Apply Euler to
with
, whose solution
decays. Euler gives
. If
, that is if
![]()
the computed values grow and oscillate in sign, while the true solution goes to zero. The method is unstable. It is not a matter of accuracy: even when the solution is almost zero after a while and does not need to be followed in detail, the step must stay small.
A problem is stiff when it contains very different time constants. A circuit with one time constant of 1 ns and another of 1 ms, simulated for a few milliseconds, would force an explicit method to take steps below 2 ns throughout: millions of steps, even after the fast transient has died away.
The answer is implicit methods, such as implicit Euler:
![]()
where the slope is evaluated at the end point. For
it gives
, which decays for any step. The price is that at each step an equation must be solved (or a nonlinear system, with Newton). SPICE uses exactly implicit methods, the implicit trapezoidal rule and Gear’s formulas, because electronic circuits are almost always stiff. When you change the integration method from “trap” to “gear” in a simulation’s options, you are choosing between two implicit methods with different stability properties.
Conservation of energy
For frictionless oscillating systems, such as an ideal LC circuit or an orbit, explicit Euler makes the energy grow at every turn and the trajectory spirals outwards; implicit Euler makes it shrink. There are methods, called symplectic (such as the Verlet method, used in molecular dynamics simulations and in video game physics engines), that conserve energy for very long times even with large steps.
8Finite differences for PDEs
The partial differential equations of the Mathematical Methods lesson can be solved by hand only on simple domains. For a heat sink of realistic shape, for the field in a semiconductor device, for a signal travelling on a line with discontinuities, numerical methods are needed. The most direct is the finite difference method: space and time are replaced by a grid of points and derivatives by difference quotients. In this lesson we apply it to the heat equation and look at consistency, stability and convergence, and at the Courant condition for waves.
Derivatives as differences
From Taylor’s expansion, with step
:
![]()
The second, centred, is more accurate for the same step, because the errors of the two sides cancel. For the second derivative, adding the expansions at
and
:
![]()
with error
. These formulas are enough to discretise almost every equation in physics.
The heat equation: the explicit scheme
on
. Introduce the grid
,
, and write
for the approximation of
. Using a forward difference in time and a centred one in space:
![]()
that is, with
,
![]()

(red) is computed from the three neighbouring values at the previous step (blue): the “stencil” of the explicit scheme.Each new value is computed from its three neighbours at the previous step: start from the initial condition and advance row by row, applying the boundary conditions at the ends. It can be programmed in a few lines, even in a spreadsheet.
Stability: 
The scheme is stable only if
![]()
Why. With
the new value is a weighted average of the three neighbours with positive weights,
: it cannot exceed the largest of the old values, so errors do not grow (discrete maximum principle). With
the central weight becomes negative, and a small point-to-point oscillation is amplified at every step: after a few dozen steps the solution blows up into a meaningless zigzag.
The practical consequence is heavy: halving
for more detail means dividing
by four, and the total work grows eightfold. As with stiff differential equations, the answer is implicit schemes: the Crank-Nicolson scheme, which averages the old and new steps, is stable for any
and has error
. At each step it needs to solve a tridiagonal linear system, which is cheap.
Consistency, stability, convergence
- A scheme is consistent if, as the steps tend to zero, the discrete equation tends to the true one (the truncation error goes to zero).
- It is stable if errors, from rounding or from the data, do not grow without bound over the steps.
- It is convergent if the numerical solution tends to the true one as the steps tend to zero.
The Lax-Richtmyer equivalence theorem states that for well-posed linear problems a consistent method is convergent if and only if it is stable. It is the central result of the whole theory, and it is the one referred to in the introduction to finite difference methods linked to this subject.
The wave equation and the Courant condition
For
, with centred differences in time and space, the explicit scheme is stable if and only if
![]()
the Courant-Friedrichs-Lewy (CFL) condition. Its meaning is physical: in one step
the wave travels
, and the scheme uses only points a distance
away. If the wave travels further than one grid point per step, the scheme cannot “see” where the information is coming from and the solution becomes unstable. The numerical domain of dependence must contain the physical one.
It is the condition that governs FDTD (finite-difference time-domain) electromagnetic simulators, used to design antennas, waveguides and high-speed printed circuit boards: with 1 mm cells and the speed of light, the time step must stay below about 2 picoseconds in three dimensions.
Two dimensions and beyond
For Laplace’s equation on a plate, the difference formula in both directions gives
![]()
each value is the average of its four neighbours, the discrete version of the mean value property of harmonic functions. Repeating this averaging over the whole grid until the values stop changing is the Jacobi method of the lesson on linear systems. For complicated geometries, with curved edges, the finite element method is preferred, which splits the domain into triangles or tetrahedra and uses Gaussian quadrature: it is the method of the structural, thermal and electromagnetic simulation programs used in industry.
9DFT and FFT
The Fourier transform of the Mathematical Methods lesson is an integral over a continuous, infinite signal. On a computer you have
samples instead. The discrete Fourier transform (DFT) is the version for sampled signals, and the FFT (Fast Fourier Transform) is the algorithm that computes it efficiently. Introduced in its modern form by Cooley and Tukey in 1965, it is considered one of the most important algorithms of the twentieth century: it is in every digital oscilloscope, in Wi-Fi, 4G and 5G, in MP3 and JPEG compression, in radar.
The DFT
Given
samples
, taken at sampling frequency
, the DFT is
![Rendered by QuickLaTeX.com \[ X_k = \sum_{n=0}^{N-1}x_n\,e^{-2\pi i\,kn/N},\qquad k = 0, 1, \dots, N - 1 \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-ef54ed75e73cbd6808048499764edd7a_l3.png)
and the inverse transform
![Rendered by QuickLaTeX.com \[ x_n = \frac1N\sum_{k=0}^{N-1}X_k\,e^{2\pi i\,kn/N} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-3bf57ea528dda71f864307e7612fdbc0_l3.png)
The coefficient
measures how much the signal looks like a sinusoid completing
periods within the window of
samples, that is at frequency
. The frequency resolution is
: telling two close frequencies apart needs long windows.

Two properties worth remembering.
- For a real signal
: the second half of the spectrum mirrors the first, and the useful frequencies run from 0 to
(the Nyquist frequency). It is the same phenomenon as aliasing. - The DFT treats the signal as if it were periodic with period
. If the window does not hold a whole number of periods, the start and end do not join up and the spectrum “spreads” over nearby bins (spectral leakage). It is reduced by multiplying the signal by a window that falls smoothly to zero at the edges (Hann, Hamming, Blackman): the “window” option of spectrum analysers and oscilloscopes.
The cost and the idea of the FFT
Computed directly, the DFT needs
sums of
terms:
complex multiplications. With
that is
operations.
The FFT exploits the structure of the exponentials. With
even, split the even- and odd-indexed samples:
![Rendered by QuickLaTeX.com \[ X_k = \sum_{m=0}^{N/2-1}x_{2m}\,e^{-2\pi i\,km/(N/2)} + e^{-2\pi i\,k/N}\sum_{m=0}^{N/2-1}x_{2m+1}\,e^{-2\pi i\,km/(N/2)} = E_k + W^k\,O_k \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-aa5006f9a093564b879eace99cd69fea_l3.png)
and
are the DFTs, of length
, of the even and odd samples, and
. Moreover, since
and
have period
and
:
![]()
One multiplication gives two coefficients (the “butterfly”). A DFT of length
becomes two DFTs of length
plus
multiplications; repeating down to length 1, with
there are
levels. The total cost is
![]()
multiplications. With
(about
): about
instead of
, a hundred thousand times fewer. It is the difference between a calculation of a few milliseconds and one of hours.
Fast convolution
Convolving two sequences of length
directly costs
operations. With the convolution theorem (lesson on the Fourier transform), take the FFT of both, multiply the spectra and take the inverse FFT: a cost proportional to
. This is how very long FIR filters are applied, how reverb effects are derived from an impulse response, and how huge integers are multiplied.
Applications
- Spectrum analysis. The FFT function of digital oscilloscopes shows the harmonics of a signal: an amplifier’s distortion or 50/60 Hz mains interference is visible at once.
- OFDM. Wi-Fi, 4G, 5G and digital TV transmit data on hundreds or thousands of orthogonal subcarriers. The transmitter builds the signal with an inverse FFT, the receiver splits it with an FFT. Without a fast algorithm these techniques could not be done in a phone.
- Compression. MP3 and AAC work on a related transform (the MDCT) and discard the components the ear cannot hear; JPEG uses the discrete cosine transform on 8×8 pixel blocks.
- Radar and sonar. The range and speed of targets are found from the frequencies in the received signal, computed with the FFT: this is how 77 GHz automotive radars work.
Zero padding and resolution
Appending zeros to the samples before the FFT (zero padding) makes the spectrum denser and nicer to look at, but it does not increase the resolution: two frequencies closer than
, with
the number of real samples, remain indistinguishable. Separating them needs a longer observation window. It is the same time-frequency uncertainty principle seen for the continuous transform.
The discrete Fourier transform (DFT): from the DTFT, inverse, properties and circular convolution proved
The discrete Fourier transform (DFT) is the transform a computer can actually compute: it takes
numbers and returns
numbers. Every digital spectrum analyser, every equaliser, every OFDM modem (Wi-Fi, 4G, 5G) and every fast filter uses it, almost always through the FFT algorithm. This in-depth study derives the DFT from the discrete-time Fourier transform (DTFT) and proves its formulas and properties: inverse transform, Parseval, circular shift, Hermitian symmetry, circular convolution and how to obtain linear convolution from it. The linked lessons explain the FFT algorithm and practical use in spectral analysis (leakage, windows, Welch’s method). The path follows the topics of Sandro Petrizzelli’s notes from which this page originated.
From the DTFT to the DFT
A sequence
has DTFT
![Rendered by QuickLaTeX.com \[ X(e^{j\omega}) = \sum_{n=-\infty}^{\infty} x[n]\,e^{-j\omega n} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-3924c9aac433909bd41e8ca3b74ae732_l3.png)
a continuous function, periodic with period
in the normalised angular frequency
. A computer cannot store a continuous function: it takes
equally spaced samples of it,
,
. If
is nonzero only for
, these samples are
![Rendered by QuickLaTeX.com \[ X[k] = X(e^{j2\pi k/N}) = \sum_{n=0}^{N-1} x[n]\,W_N^{kn},\qquad W_N = e^{-j2\pi/N} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-0776dd0b3dff4ea6153deff3db7aee3a_l3.png)
This is the
-point DFT. The number
is an
-th root of unity:
, and its powers are
equally spaced points on the unit circle.

Theorem (sampling in frequency is repeating in time). If
is longer than
, the samples
of its DTFT coincide with the DFT of the sequence
,
: the parts of
beyond
overlap (time aliasing).
Proof. Split the DTFT sum into blocks of
samples,
with
:
. Since
, what remains is
, the DFT of
. ∎
It is the dual of the sampling theorem: sampling in time makes the spectrum periodic, sampling the spectrum makes the signal periodic. This is why the DFT always treats the block of
samples as if it were one period of a periodic signal: all the properties that follow are “circular”.
The inverse transform
Theorem.
.
Proof. A lemma is needed, the orthogonality of discrete exponentials:
if
is a multiple of
, otherwise 0. Indeed in the first case every term equals 1; in the second
and the geometric sum is
. Now substitute the definition:
![Rendered by QuickLaTeX.com \[ \frac{1}{N}\sum_{k=0}^{N-1}\Big(\sum_{m=0}^{N-1} x[m]W_N^{km}\Big)W_N^{-kn} = \frac{1}{N}\sum_{m=0}^{N-1} x[m]\sum_{k=0}^{N-1} W_N^{k(m - n)} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-1eae07dd0e0acdf74616968470658ea9_l3.png)
The inner sum equals
only for
(with
between 0 and
,
is a multiple of
only if it is zero):
remains. ∎
In matrix form
with
, and the theorem says
: the matrix
is unitary. Parseval’s theorem follows immediately:
![Rendered by QuickLaTeX.com \[ \sum_{n=0}^{N-1}|x[n]|^2 = \frac{1}{N}\sum_{k=0}^{N-1}|X[k]|^2 \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-1fdffcd952bacd263bf00d7c93e696cc_l3.png)
because a unitary matrix preserves the norm:
. Energy can be measured equally in time or in frequency.
The properties, proved
In all that follows indices are taken modulo
:
is the remainder of
divided by
.
Linearity.
: the definition is a sum.
Circular time shift.
.
Proof.
; with
, as
runs over
so does
(in another order), and
because
. The sum becomes
. ∎
The delay only changes the phase of the coefficients, not the magnitude. But it is a circular delay: samples leaving on the right re-enter on the left.

Frequency shift (modulation).
: same proof with the roles swapped. Multiplying by a complex exponential shifts the spectrum: it is the principle of frequency conversion in digital receivers.
Hermitian symmetry. If
is real,
.
Proof.
, because
. For real
, conjugation only changes the sign of the exponent:
. ∎
So real part and magnitude are symmetric about
, imaginary part and phase antisymmetric: for a real signal the coefficients from 0 to
are enough, and the “real” FFT does half the computation. The coefficient
(with even
) is the Nyquist frequency and is real.

Circular symmetry. If moreover
(even in the circular sense, i.e.
), the DFT is real; if it is odd, purely imaginary. It follows from the previous property: for even
,
.
Circular convolution
Theorem. The product of DFTs corresponds to circular convolution:
![Rendered by QuickLaTeX.com \[ Y[k] = X[k]H[k] \;\leftrightarrow\; y[n] = \sum_{m=0}^{N-1} x[m]\,h[(n - m)_N] = (x \circledast h)[n] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-faa3a5028b77240fadbccc845b68a93b_l3.png)
Proof. Compute the DFT of
and use the circular shift:
. ∎
Filtering a signal is instead a linear convolution,
, with length
if
and
have lengths
and
. Circular convolution on
points is the linear one “wrapped around”: samples beyond
are added at the start (the frequency-sampling theorem applied to
).
Example.
,
. The linear convolution is
. With an
point DFT the last 3 wraps onto
:
, a wrong result for a filter. With
there is no overlap and
is obtained again.

Practical rule: to filter with the FFT, pad
and
with zeros up to
. For long signals the signal is split into blocks and the overlap-add and overlap-save methods are used, which reassemble the blocks without errors; with large
the cost,
instead of
, is much lower than direct convolution.
Two DFTs to know by heart
Rectangular pulse of
samples on
points: with the geometric sum
![Rendered by QuickLaTeX.com \[ X[k] = \sum_{n=0}^{L-1} W_N^{kn} = \frac{1 - W_N^{kL}}{1 - W_N^k} = e^{-j\pi k(L - 1)/N}\,\frac{\sin(\pi kL/N)}{\sin(\pi k/N)} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-aa9f0b84b1007c1d76c95322d808cbef_l3.png)
(factoring
in the numerator and
in the denominator). The magnitude is the Dirichlet kernel, the discrete version of the sinc: for
,
it is
. It is also the response of the rectangular window, the origin of spectral leakage.
Cosine on a bin.
: by orthogonality the DFT equals
at
and at
, zero elsewhere. If the frequency does not fall exactly on a bin the DFT has values at all
: this is spectral leakage, covered in the spectral analysis lesson.
Zero padding
Padding a block of
samples with zeros up to
does not add information: by the first theorem, the
-point DFT samples the same DTFT more densely (figure at the top, 8 and 16 points). It helps to read peak positions better and to reach a power of 2 for the FFT, but the ability to separate two close frequencies depends only on the duration
of the observed signal: about
.
Checking in Python
import numpy as np
def dft(x):
"""DFT from the definition: X[k] = sum x[n] e^{-j 2 pi k n / N}."""
N = len(x)
n = np.arange(N)
W = np.exp(-2j * np.pi * np.outer(n, n) / N) # Fourier matrix
return W @ x
def idft(X):
N = len(X)
n = np.arange(N)
return np.exp(2j * np.pi * np.outer(n, n) / N) @ X / N
rng = np.random.default_rng(1)
x = rng.standard_normal(8)
X = dft(x)
print("equal to np.fft.fft:", np.allclose(X, np.fft.fft(x)))
print("exact inverse:", np.allclose(idft(X), x))
print("Parseval:", np.isclose(np.sum(x**2), np.sum(abs(X)**2) / 8))
print("Hermitian symmetry X[N-k] = X*[k]:", np.allclose(X[1:][::-1], np.conj(X[1:])))
m = 3
print("circular shift:", np.allclose(dft(np.roll(x, m)), np.exp(-2j * np.pi * np.arange(8) * m / 8) * X))
# circular versus linear convolution
a, h = np.array([1.0, 2, 3]), np.array([1.0, 1])
lin = np.convolve(a, h)
circ3 = np.real(idft(dft(a) * dft(np.r_[h, 0])))
circ4 = np.real(idft(dft(np.r_[a, 0]) * dft(np.r_[h, 0, 0])))
print("linear:", lin, " circular N=3:", np.round(circ3, 6), " circular N=4:", np.round(circ4, 6))
# DFT of a rectangular pulse of L = 4 samples on N = 8 points: Dirichlet kernel
L, N = 4, 8
r = np.r_[np.ones(L), np.zeros(N - L)]
k = np.arange(1, N)
dirichlet = np.exp(-1j * np.pi * k * (L - 1) / N) * np.sin(np.pi * k * L / N) / np.sin(np.pi * k / N)
print("rectangle, Dirichlet formula:", np.allclose(dft(r)[1:], dirichlet), " |X| =", np.round(abs(dft(r)), 3))
# cosine falling exactly on bin 2
c = np.cos(2 * np.pi * 2 * np.arange(N) / N)
print("cosine on bin 2:", np.round(abs(dft(c)), 6))All checks print True; the 3-point circular convolution gives
and the 4-point one
, equal to the linear one; the magnitude of the rectangle and the cosine on bin 2 (value 4 at
and
) match the formulas. The DFT from the definition costs
multiplications: for
it does not matter, for
it does, and this is the reason for the FFT algorithm, explained in the linked lesson.
∑Formula sheet
Floating-point arithmetic, errors and conditioning
Floating-point numbers
![]()
![]()
Conditioning of a problem
![]()
Root finding for nonlinear equations
Newton's method
![]()
Proof of quadratic convergence
![]()
![]()
The secant method
![]()
Nonlinear systems
![]()
Numerical linear algebra: direct and iterative methods
LU factorisation
![]()
![]()
![Rendered by QuickLaTeX.com \[ A = \begin{pmatrix} 2 & 1 & 1\\ 4 & 3 & 3\\ 8 & 7 & 9\end{pmatrix} = \begin{pmatrix} 1 & 0 & 0\\ 2 & 1 & 0\\ 4 & 3 & 1\end{pmatrix}\begin{pmatrix} 2 & 1 & 1\\ 0 & 1 & 1\\ 0 & 0 & 2\end{pmatrix} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-84742d209aa5acdd0a8e0d47ed364837_l3.png)
Symmetric positive definite matrices: Cholesky
![]()
Iterative methods
![Rendered by QuickLaTeX.com \[ x_i^{(k+1)} = \frac{1}{a_{ii}}\Big(b_i - \sum_{j \ne i}a_{ij}\,x_j^{(k)}\Big) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-91cf97e1c756c2230a8e90e218f6596d_l3.png)
The residual is not enough
![]()
Interpolation and splines
The interpolating polynomial
![Rendered by QuickLaTeX.com \[ \ell_i(x) = \prod_{j \ne i}\frac{x - x_j}{x_i - x_j} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-8023c75bdf21158b90c262f216457303_l3.png)
![Rendered by QuickLaTeX.com \[ p_n(x) = \sum_{i=0}^{n}y_i\,\ell_i(x) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-9122bfaf5654256c569edce72232a445_l3.png)
The interpolation error
![Rendered by QuickLaTeX.com \[ f(x) - p_n(x) = \frac{f^{(n+1)}(\xi)}{(n + 1)!}\,\prod_{i=0}^{n}(x - x_i) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-03950ea35a952bde177b8ff58b528f68_l3.png)
Runge's phenomenon
![]()
Chebyshev nodes
![]()
Least squares approximation
The problem
![Rendered by QuickLaTeX.com \[ S(c_0, c_1) = \sum_{i=1}^{m}\big(y_i - c_0 - c_1x_i\big)^2 \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-9e323fb24af6902118c595adaae45057_l3.png)
The normal equations
![]()
![Rendered by QuickLaTeX.com \[ \begin{cases} m\,c_0 + \left(\sum x_i\right)c_1 = \sum y_i\\ \left(\sum x_i\right)c_0 + \left(\sum x_i^2\right)c_1 = \sum x_iy_i \end{cases} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-e65482a68fff05c518ec43678b6f3f33_l3.png)
![]()
Matrix form
![]()
Numerical integration
The trapezoidal rule
![Rendered by QuickLaTeX.com \[ \int_a^b f\,dx \approx T_h = h\left[\frac{f_0}{2} + f_1 + f_2 + \dots + f_{n-1} + \frac{f_n}{2}\right] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-603d604bf7f030afc80dfe7bcd64582a_l3.png)
![Rendered by QuickLaTeX.com \[ \int_a^b f\,dx - T_h = -\frac{(b - a)\,h^2}{12}\,f''(\xi) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-a512041865175688f6028c305e6fb14e_l3.png)
Simpson's rule
![Rendered by QuickLaTeX.com \[ \int_a^b f\,dx \approx S_h = \frac h3\Big[f_0 + 4f_1 + 2f_2 + 4f_3 + \dots + 2f_{n-2} + 4f_{n-1} + f_n\Big] \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-3d508dae5dca6f47628562a2b4a29534_l3.png)
![]()
Proof: Simpson from the trapezoidal rule
![]()
Gaussian quadrature
![Rendered by QuickLaTeX.com \[ \int_{-1}^{1}f\,dx \approx f\!\left(-\tfrac{1}{\sqrt3}\right) + f\!\left(\tfrac{1}{\sqrt3}\right) \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-2e263196147b29d289a6c4302591a942_l3.png)
Integrals of sampled signals
![Rendered by QuickLaTeX.com \[ V_{rms} = \sqrt{\frac{1}{T_p}\int_0^{T_p}v^2(t)\,dt} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-9892e24a4805e65ee1e21d79ca70d354_l3.png)
Numerical solution of ODEs
The problem
![]()
The explicit Euler method
![]()
Runge-Kutta methods
![]()
![Rendered by QuickLaTeX.com \[ \begin{aligned} k_1 &= f(t_n, y_n) & k_2 &= f\!\left(t_n + \tfrac h2, y_n + \tfrac h2k_1\right)\\ k_3 &= f\!\left(t_n + \tfrac h2, y_n + \tfrac h2k_2\right) & k_4 &= f(t_n + h, y_n + hk_3) \end{aligned} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-89e8f309a8a58016b73628c1a11db376_l3.png)
![]()
Stability and stiff problems
![]()
![]()
Finite differences for PDEs
Derivatives as differences
![]()
![]()
The heat equation: the explicit scheme
![]()
![]()
Stability: 
![]()
The wave equation and the Courant condition
![]()
Two dimensions and beyond
![]()
DFT and FFT
The DFT
![Rendered by QuickLaTeX.com \[ X_k = \sum_{n=0}^{N-1}x_n\,e^{-2\pi i\,kn/N},\qquad k = 0, 1, \dots, N - 1 \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-ef54ed75e73cbd6808048499764edd7a_l3.png)
![Rendered by QuickLaTeX.com \[ x_n = \frac1N\sum_{k=0}^{N-1}X_k\,e^{2\pi i\,kn/N} \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-3bf57ea528dda71f864307e7612fdbc0_l3.png)
The cost and the idea of the FFT
![Rendered by QuickLaTeX.com \[ X_k = \sum_{m=0}^{N/2-1}x_{2m}\,e^{-2\pi i\,km/(N/2)} + e^{-2\pi i\,k/N}\sum_{m=0}^{N/2-1}x_{2m+1}\,e^{-2\pi i\,km/(N/2)} = E_k + W^k\,O_k \]](https://www.electronics-engineering.com/wp-content/ql-cache/quicklatex.com-aa5006f9a093564b879eace99cd69fea_l3.png)
![]()
![]()