Skip to content
PostNumerical Computation / Lecture

Numerical Computation Fundamentals

2025-10-03
Back to Blog

Numerical Computation Fundamentals

Binary numbers

Binary numbers are expressed as

...b2b1b0.b1b2...

where each binary digit, or bit, is 0 or 1. The base 10 equivalent to the number is

...b222+b121+b020+b121+b222...

EXAMPLE:
The decimal number 4 is expressed as (100.)2 in base 2, and 3/4 is represented as (0.11)2.

Decimal to Binary

To convert a decimal number to binary, it is simplest to break the number into integer and fractional parts and convert each part separately.

Integer part. Convert decimal integers to binary dividing by 2 successively and recording the remainders.

shell
53 ÷ 2 = 26 R 1
26 ÷ 2 = 13 R 0
13 ÷ 2 = 6  R 1
6  ÷ 2 = 3  R 0
3  ÷ 2 = 1  R 1
1  ÷ 2 = 0  R 1

Therefore, the base 10 number 53 can be written in bits as 110101, denoted as 5310=1101012.

Fractional part. Convert (0.7)10 to binary by reversing the preceding steps. Multiply by 2 successively and record the integer parts, moving away from the decimal point to the right.

shell
0.7 × 2 = 1.4 1
0.4 × 2 = 0.8 0
0.8 × 2 = 1.6 1
0.6 × 2 = 1.2 1
0.2 × 2 = 0.4 0
0.4 × 2 = 0.8 0
...

Therefore, (0.7)10=(.1011001100110)2=(.10110)2

where overbar notation is used to denote infinitely repeated bits. Putting the two parts together, we conclude that (53.7)10=(110101.10110)2.

Binary to Decimal

To convert a binary number to decimal, it is again best to separate into integer and fractional parts.

Integer part: Simply add up powers of 2. The binary number (10101)2 is simply

124+023+122+021+120=(21)10.

Fractional part: If the fractional part is finite, proceed the same way

(.1011)2=12+18+116=(1116)10.

When the fractional part is not a finite base 2 expansion.

EXAMPLE:

When the fractional part is not a finite base 2 expansion, we can use the shift property of multiplication by 2.

Suppose x=(0.1011)2,

24x=1011.1011x=0000.1011

Subtracting yields

(241)x=(1011)2=(11)10

Then solve for x to find

x=(0.1011)2=(1115)10.

Floating point representation of real numbers

A floating point number consists of three parts: the sign (+ or −), a mantissa, which contains the string of significant bits, and an exponent. The three parts are stored together in a single computer word. The form of a normalized floating point number is

±1.bbbb×2p

where each of the N b's is 0 or 1, and p is an M-bit binary number representing the exponent. Normalization means that the leading bit must be 1.

The double precision format, common in C compilers, Python, and MATLAB, uses exponent length M=11 and mantissa length N=52.

The floating-point form of y is obtained by terminating the mantissa of y at k decimal digits.

Chopping

Chop off the digits dk+1dk+2

fl(y)=0.d1d2dk×10n

Rounding

Adds 5×10n(k+1) to y and then chops the result to obtain a number of the form

fl(y)=0.δ1δ2δk×10n

When dk+15, we add 1 to dk; when dk+1<5, we simply chop off all but the first k digits.

EXAMPLE:

(a) The floating-point form of π using five-digit chopping is

fl(π)=0.31415×101=3.1415

(b) The floating-point form of π using five-digit rounding is

fl(π)=0.31416×101=3.1416

Correct within 𝑝 decimal places

A Solution is correct within p decimal places if the error is less than 0.5×10p

Absolute Error & Relative Error

DEFINITION: Let xc be a computed version of the exact quantity x. Then

absolute error=|xcx|,

and

relative error=|xcx||x|

EXAMPLE:

(a) xc=0.3100×101,x=0.3000×101

absolute error=|xcx|=|0.3100×1010.3000×101|=0.1relative error=|xcx||x|=0.1|0.3000×101|=0.3333×101

(b) xc=0.3100×104,x=0.3000×104

absolute error=|xcx|=|0.3100×1040.3000×104|=0.1×103relative error=|xcx||x|=0.1×103|0.3000×104|=0.3333×101

Same relative error, 0.3333×101, occurs for widely varying absolute errors. As a measure of accuracy, the absolute error can be misleading and the relative error more meaningful because the relative error takes into consideration the size of the value.

Loss of significance

Assume that through considerable effort, as part of a long calculation, we have determined two numbers correct to seven significant digits, and now need to subtract them:

123.4567123.4566=000.0001

Let’s write the subtraction in normalized decimal float-point:

0.1234567×1030.1234566×103=0.1×103

The subtraction problem began with two input numbers that we knew to seven-digit accuracy, and ended with a result that has only one-digit accuracy. It is called loss of significance, and in many cases this can be avoided by restructuring the calculation.

Convergence

To calculate convergence, we usually try to estimate the error in the numerical solution compared to the actual solution. We try to find out how fast this error is decreasing (or increasing).

DEFINITION:

Suppose {βn}n=1 is a sequence converging to zero, and {an}n=1 converges to a number α. If a positive constant K exists with

|anα|K|βn|,for large n,

then we say that {an}n=1 converges to α with rate of convergence O(βn), indicated by an=α+O(βn).


DEFINITION:
Let εn be the error in the nth iteration of the algorithm. That is, εn=|anα|.

DEFINITION:
We say that the algorithm has linear convergence if |εn+1|=C|εn|.

DEFINITION:
We say that the algorithm has quadratic convergence if |εn+1|=C|εn|2.


设误差为

ei=|xir|

其中 r 为方程 f(x)=0 的真根,xi 为第 i 次迭代的近似值。

若存在常数 p>0C>0,使得

limi|ei+1||ei|p=C<,

则称该方法具有 p 阶收敛(order of convergence = p)

收敛类型条件特征示例
线性收敛(Linear)p=1, 0<C<1误差按比例缩小二分法、FPI
超线性收敛(Superlinear)1<p<2介于线性与二次之间割线法
二次收敛(Quadratic)p=2误差平方级减少牛顿法

Review of calculus

Limits and Continuity

pHAdae

DEFINITION:

A function f defined on a set X of real numbers has the limit L at x0, written

limxx0f(x)=L,

if, given any real number ε>0, there exists a real number δ>0 such that

|f(x)L|<ε

whenever xX and

0<|xx0|<δ.

DEFINITION:
Let f be a function defined on a set X of real numbers and x0X. Then f is continuous at x0 if

limxx0f(x)=f(x0).

The function f is continuous on the set X if it is continuous at each number in X.

DEFINITION:
Let {xn}n=1 be an infinite sequence of real numbers. This sequence has the limit x (converges to x) if, for any ε>0, there exists a positive integer N(ε) such that |xnx|<ε whenever n>N(ε). The notation

limnxn=x,orxnx as n,

means that the sequence {xn}n=1 converges to x.

THEOREM:
If f is a function defined on a set X of real numbers and x0X, then the following statements are equivalent:

a. f is continuous at x0;

b. If {xn}n=1 is any sequence in X converging to x0, then

limnf(xn)=f(x0).

Differentiability

mV40KbDEFINITION:
Let f be a function defined on an open interval containing x0. The function f is differentiable at x0 if

f(x0)=limxx0f(x)f(x0)xx0

exists. The number f(x0) is called the derivative of f at x0. The function that has a derivative at each number in a set X is differentiable on X.

THEOREM:
If the function f is differentiable at x0, then f is continuous at x0.

THEOREM (Rolle’s Theorem):
Suppose fC[a,b] and f is differentiable on (a,b). If f(a)=f(b), then a number c in (a,b) exists with

f(c)=0.

E2kCVO

THEOREM (Mean Value Theorem):
If fC[a,b] and f is differentiable on (a,b). Then a number c in (a,b) exists with

f(c)=f(b)f(a)ba.

pyMJeQ

THEOREM (Intermediate Value Theorem):
If fC[a,b] and K is any number between f(a) and f(b), then there exists a number c in (a,b) for which

f(c)=K.

McVz7p

Integration

DEFINITION:
The Riemann integral of the function f on the interval [a,b] is the following limit, provided it exists:

abf(x)dx=limΔxi0i=1nf(zi)Δxi,

where the numbers x0,x1,...,xn satisfy a=x0x1...xn=b, where Δxi=xixi1, for each i=1,2,...,n, and zi is arbitrarily chosen in the interval [xi1,xi].

i3Fv3n

Taylor Polynomials and Series

THEOREM (Taylor’s Theorem):
Suppose fCn[a,b], f(n+1) exists on [a,b], and x0[a,b]. For every x[a,b], there exists a number ξ(x) between x0 and x with

f(x)=Pn(x)+Rn(x),

where

Pn(x)=f(x0)+f(x0)(xx0)+f(x0)2!(xx0)2++f(n)(x0)n!(xx0)n=k=0nf(k)(x0)k!(xx0)k

and

Rn(x)=f(n+1)(ξ(x))(n+1)!(xx0)n+1.

Here Pn(x) is called the nth Taylor polynomial for f about x0, and Rn(x) is called the remainder term (or truncation error) associated with Pn(x).

The infinite series obtained by taking the limit of Pn(x) as n is called the Taylor series for f about x0. In the case x0=0, the Taylor polynomial is often called a Maclaurin polynomial, and the Taylor series is often called a Maclaurin series.

The term truncation error in the Taylor polynomial refers to the error involved in using a truncated, or finite, summation to approximate the sum of an infinite series.

Example

Let f(x)=cosx and x0=0. Determine
a. The second Taylor polynomial for f about x0; and
b. The third Taylor polynomial for f about x0.


SOLUTION:

f(x)=sinx, f(x)=cosx, f(x)=sinx, and f(4)(x)=cosx,

So

f(0)=1, f(0)=0, f(0)=1, and f(0)=0.

a.

cosx=f(0)+f(0)x+f(0)2!x2+f(ξ(x))3!x3

where ξ(x) is some number between 0 and x.

cosx=112x2+16x3sinξ(x),

Y5eicX

When x=0.01, this becomes

cos0.01=112(0.01)2+16(0.01)3sinξ(0.01),=0.99995+1066sinξ(0.01).

Since 1sinξ(0.01)1,

0.99994998<0.999951.6×107cos0.010.99995+1.6×107<0.9999502.

Furthermore, since |sinx||x|, we have

0.01sinξ(0.01)0.01.

Substitute into the remainder, the error is in the region

[1.6×109,1.6×109].

b. Since f(0)=0, the third Taylor polynomial with remainder term about x0=0 is

cosx=112x2+124x4cosξ(x),

where 0<ξ(x)<0.01.

The approximating polynomial remains the same, and the approximation is still 0.99995, but we now have much better accuracy assurance. Since 1cosξ(x)1 for all x, we have

|124x4cosξ(x)|124(0.01)4(1)4.2×1010.

So,

0.99994999958<0.999954.2×1010cos0.010.99995+4.2×1010<0.99995000042.