Docsity

Mathematical methods for bioengineering, Dispense di Metodi Matematici per l'Ingegneria

Anteprima parziale del testo

Scarica Mathematical methods for bioengineering e più Dispense in PDF di Metodi Matematici per l'Ingegneria solo su Docsity!

MATHEMATICAL METHODS FOR BIOENGINEERING

LECTURE NOTES

ALBERTO SORRENTINO DIPARTIMENTO DI MATEMATICA, UNIVERSIT A DI GENOVA`

Part I: Basic mathematical tools

A matrix with m rows and n columns such as this one is said to have size m × n. Two matrices with the same size can be summed

A + B =

a(1,1)^ + b(1,1)^ a(1,2)^ + b(1,2)^... a(1,n)^ + b(1,n)

............ a(m,1)^ + b(m,1)^...... a(m,n)^ + b(m,n)

Multiplication of matrices is a bit less straightforward: given two matrices A and B, one can compute A · B only when the number of columns of A is equal to the number of rows of B; suppose than that A has size m × n and B has size n × p: the product A · B is a matrix of size m × p, defined as follows:

A · B =

Pn k=1 a

(1,k) (^) b(k,1) Pn k=1 a

(1,k) (^) b(k,2) (^)... Pn k=1 a

(1,k) (^) b(k,p) Pn k=1 a

(2,k) (^) b(k,1) Pn k=1 a

(2,k) (^) b(k,2) (^)... Pn k=1 a

(2,k) (^) b(k,p)

P^...^...^...^... n k=1 a

(m,k) (^) b(k,1) Pn k=1 a

(m,k) (^) b(k,2) (^)... Pn k=1 a

(m,k) (^) b(k,p)

In words, the i, j-element of the product is the scalar product between the i-th row of matrix A and the j-th column of matrix B. This multiplication is clearly non-commutative, i.e. B · A ̸= A · B; in fact, B · A cannot actually be computed unless the number of columns of B equals the number of rows of A! For square matrices, one can define the identity matrix I, i.e. a matrix such that A·I = I ·A = A; the identity matrix can be easily shown to be

I =

In addition, for square matrices one can define the inverse A−^1 A−^1 · A = I = A · A−^1

Remarkably, if X = AB is the product of two invertible matrices, then X−^1 = B−^1 A−^1 , i.e. the order is reversed. Matrices can be conveniently used to represent operations/transformations on (column) vectors, through the matrix vector product

Example 1. For example, the following matrix “kills” the second component of a vector:

A =

v = (v(1), v(2))

and we get A · v = (v(1), 0)

the following matrix “flips” the components of a vector:

A =

v = (v(1), v(2))

and we get

A · v = (v(2), v(1))

1.1.3. Determinant. The determinant of a (square) matrix is a scalar; for a 2 × 2 matrix it is obtained as

det(A) = a(1,1)a(2,2)^ − a(1,2)a(2,1)

i.e. it is the difference between the product of the diagonal values and the product of the off-diagonal values; it is easy to see that the determinant is zero if the two rows of the matrix are proportional to each other. For a 3 × 3 matrix, the determinant is obtained as

det(A) = = a(1,1)(a(2,2)a(3,3)^ − a(3,2)a(2,3)) +

  • a(1,2)(a(2,3)a(3,1)^ − a(3,3)a(2,1)) +
  • a(1,3)(a(2,1)a(3,2)^ − a(3,1)a(2,2))

The determinant is non-zero if and only if the matrix is invertible. The following holds det(A · B) = det(A) det(B) The determinant of the identity matrix is 1 (one). If two columns are swapped, the determinant changes sign. The determinant of the transpose of a matrix is equal to the determinant of the original matrix. If one column is multiplied by a scalar, then the determinant is multiplied by the same scalar. The determinant can also be interpreted as the volume transformation factor induced by the action of the matrix. This can be easily seen by taking the unit square (side = one, area = one) with a vertex in the origin, and the corresponding transformed points: the area of the transformed figure is equal to the determinant of the transformation matrix.

1.1.4. Eigenvalues and eigenvectors. A vector v is said to be an eigenvector of A if a scalar λ exists such that

Av = λv ;

if this happens, then λ is said to be an eigenvalue of A. In words, the former equation is telling us that the action of A on v is just a multiplication by a scalar: i.e., the direction of v is not affected by the action of A. Eigenvalues can be obtained by solving

det(A − λI) = 0

1.2.2. Rotations in 2D. We first consider rotations in 2D. Suppose we have a point in the Cartesian plane, of coordinates (x, y); where does this point end up after a rotation of an angle θ? (we recall that it is customary to assume that a rotation is positive when it is anticlockwise and negative otherwise.) It is simple to show that the point of coordinates (x, y) is moved by a rotation of θ onto the point of coordinates (x′, y′) defined by

(1) x′^ = x cos θ − y sin θ y′^ = x sin θ + y cos θ

Now this is a linear transformation of (x, y) onto (x′, y′) that can be written in matrix form as  x′ y′

cos θ − sin θ sin θ cos θ

x y

Therefore, we can represent a rotation of θ through a matrix R(θ)

R(θ) =

cos θ − sin θ sin θ cos θ

A few important observations are in order. If we apply two consecutive rotations R(α) and R(β), we obtain

R(α)R(β) =

cos α − sin α sin α cos α

cos β − sin β sin β cos β

cos α cos β − sin α sin β −(cos α sin β + sin α cos β) sin α cos β + cos α sin β − sin α sin β + cos α cos β

and this, using the formulas for sum of angles in sines and cosines, results in

cos(α + β) − sin(α + β) sin(α + β) cos(α + β)

= R(α + β)

which is again a rotation matrix of the angle α + β. This is a pleasant result: two subsequent rotations correspond to a single rotation of the sum of the angles. 2D rotations are commutative! Since R(α)R(β) = R(α+β), we also have R(β)R(α) = R(β +α) = R(α + β) = R(α)R(β). Rotation matrices are orthogonal matrices, i.e. their rows and columns are orthonormal vectors! This is easy to show. An other way to write this down is to write

(2) R(θ)T^ R(θ) = I

where R(θ)T^ is the transpose of R(θ). Importantly, equation (2) implies that R(θ)T^ is also the inverse of R(θ)! Again, this is consistent with the fact that the inverse of a rotation of an angle θ

is a rotation of −θ, because

R(θ)T^ =

cos θ sin θ − sin θ cos θ

cos(−θ) − sin(−θ) sin(−θ) cos(−θ)

= R(−θ)

1.2.3. The homogeneous transformation matrix. We now show how to combine 2D rotations and translations in a single matrix, of augmented size, that is capable of representing rotations and translations in a unique operation, using a mathematical trick. Let us consider a rotation of θ and translation of (xT , yT )

(x, y) → (cos θx − sin θy + xT , sin θx + cos θy + yT )

can be obtained by considering the inflated matrix

T =

cos θ − sin θ xT sin θ cos θ yT 0 0 1

where the last column contains the components of the translation vector, and the last row contains two zeroes; this inflated matrix will act on the augmented vector 

x y 1

to produce the result we are looking for. The very same technique can be applied to the 3D case; here, the rotation matrix is augmented and becomes a 4 × 4 matrix. This representation is often referred to as the homogeneous transformation matrix and has several important properties.

The inverse of a homogeneous transformation matrix is also a homogeneous transformation ma- trix. We can compactly write T =

R p 0 1

where R is the 2 × 2 rotation matrix and p the 2 × 1 translation vector. Then by imposing T T −^1 = I

we get (^)  R p 0 1

A b 0 1

I 0

so that RA = I −→ A = R−^1 = RT

and Rb + p = 0 −→ b = R−^1 p = RT^ p

1.2.5. Rotations in 3D: rotation vector. A fundamental result concerning rotations is expressed by Euler’s theorem:

Theorem 1. (Euler’s theorem) When a sphere is moved around its centre it is always possible to find a diameter whose direction in the displaced position is the same as in the initial position.

Proof. □

Importantly, Euler’s theorem guarantees that any rotation (possibly product of rotations) is a rotation about some axis. In other words, no matter how many rotations you perform, you will always find a direction left unchanged. As a consequence of Euler’s theorem, any rotation can be defined giving just three numbers. One possible way to represent a rotation is then through the rotation vector, defined as follows

(4) r = θe = θ

ex ey ez

where θ is the rotation angle and the versor e is the unit vector (therefore having only two degrees of freedom) aligned with the rotation axis. Using the rotation vector. A convenient way to use the rotation vector formalism is by Rodrigues’ formula: given a rotation versor e and an angle θ, one can rotate the generic vector v around the axis defined by e using the following formula

(5) v′^ = v cos θ + e × v sin θ + (1 − cos θ)(e · v)e

1.2.6. Rotations in 3D: relationship between matrix and Euler representations. Suppose you are given the rotation matrix and want to find the rotation vector (Euler representation). We notice that Euler’s theorem corresponds to the claim that there always exist a vector that is left untouched by the rotation. In matrix language, this corresponds to the claim that rotation matrices always have one eigenvalue equal to one: R(θ)v = v

Clearly, the vector v left untouched by the rotation will lie along the rotation axis. Therefore, in order to find the rotation axis given a rotation matrix, it is enough to calculate the eigenvector corresponding to eigenvalue 1. In order to find the rotation angle (so that one can complete the Euler representation), we can:

  • calculate the trace of R(θ); indeed, from the properties of the trace we have tr(R(θ)) = 1 + 2 cos θ
  • calculate the trace tr(KvR) = −2 sin θ (see below the definition of matrix Kv)

and one immediately gets the rotation angle θ. The advantage of this representation is clearly its compactness: only three numbers are given, which is exactly the number of free parameters in a rotation. Unfortunately, we recall here that rotations do not behave really “as vectors”: the combined rotation corresponding to two rotation vectors r 1 and r 2 cannot be obtained as the vector sum of r 1 and r 2.

We also briefly review how to go in the other direction, i.e. from the rotation vector to the rotation matrix representation. Given a unit vector v representing the rotation axis, we define the cross-product matrix Kv as the matrix that realizes the cross product, i.e.

Kvw = v × w ∀w ∈ R^3

It is easy to show that

Kv =

0 −v(3)^ v(2) v(3)^0 −v(1) −v(2)^ v(1)^0

Then the rotation of θ around the axis defined by v is represented by the matrix

R(θ) = eθKv^ =

X^ ∞

i=

(θKv)i i!

or equally by R(θ) = I + sin θKv + (1 − cos θ)K v^2

1.2.7. Rotations in 3D: Quaternions. An additional representation of rotations can be achieved using so called quaternions. Quaternions are a specific way to arrange and treat a sequence of four numbers: the first number is treated as a scalar, while the remaining three are treated as a 3D vector. A quaternion is typically written as

q = q 0 + q 1 i + q 2 j + q 3 k

where i j and k are symbols satisfying the following rules

i^2 = j^2 = k^2 = − 1 ij = k = −ji jk = i = −kj ki = j = −ik

Once these rules are defined, it is straightforward to compute the product between two quaternions q and p as p · q = (p 0 + p 1 i + p 2 j + p 3 k)(q 0 + q 1 i + q 2 j + q 3 k) = = (q 0 p 0 + q 1 p 1 i^2 + q 2 p 2 j^2 + q 3 p 3 k^2 )+

  • (q 0 p 1 i + q 1 p 0 i + q 2 p 3 jk + q 3 p 2 kj)+
  • (q 0 p 2 j + q 2 p 0 j + q 1 p 3 ik + q 3 p 1 ki)+
  • (q 0 p 3 k + q 3 p 0 k + q 1 p 2 ij + q 2 p 1 ji) = = (q 0 p 0 − q 1 p 1 − q 2 p 2 − q 3 p 3 )+
  • (q 0 p 1 + q 1 p 0 + q 2 p 3 − q 3 p 2 )i+
  • (q 0 p 2 + q 2 p 0 − q 1 p 3 + q 3 p 1 )j+
  • (q 0 p 3 + q 3 p 0 + q 1 p 2 − q 2 p 1 )k Given a quaternion q = q 0 + q 1 i + q 2 j + q 3 k one can define its conjugate q∗^ = q 0 − q 1 i − q 2 j − q 3 k
  1. Iterative algorithms We now consider the problem of determining the solutions of

(7) f (x) = 0 ;

in general there are no closed form solutions: we will study techniques (algorithms) that will construct approximations of the solution with a given precision degree.

2.1. Bisection. Bisection is the most elementary approach to finding roots of (7). It only requires that the function f (x) be continuous and that an interval [a, b] is known such that

(8) f (a) f (b) < 0

In this case one knows that at least one solution x∗^ exists in [a, b], and one can proceed by repeatedly halving the interval, each time considering the subinterval whose extrema, with abuse of notation still denoted a and b, satisfy (8). The exact location of the root is rarely found in practice, and a stopping criterion is needed to avoid infinite iterations. Typical stopping criteria are: (i) when the interval is smaller than a required threshold ϵ, and/or (ii) when the (absolute) value of the function at the extrema is smaller than a required threshold fϵ. Input: ϵ, a, b t.c. a < b.

  1. c =

a + b 2

  1. f (a)f (c)

< 0 a = a, b = c = 0 x∗^ = c STOP

0 a = c, b = b

  1. |b − a| < ϵ and/or f (a) < fϵ, f (b) < fϵ

N O goto 1) SI x∗^ = c STOP After n steps, the length of the interval is |b − a|/ 2 n, therefore the stopping criterion on the interval length is verified when

b − a 2 n^

< ϵ =⇒ n > log 2

|b − a| ϵ The method is very simple and general, with little assumptions on the function f ; on the other hand it is relatively slow: in order to obtain one more significant digit, i.e. to reduce the error of a factor 10, more than three iterations are needed.

2.2. Linear approximation methods. The idea is to select a starting point x 1 and construct subsequent approximations xk of the root x∗^ by replacing the function f (x) with a linear function, and (easily!) finding the root of the linear approximation.

2.2.1. Chords method. The simplest choice is to use a linear function that takes value f (xk) when x = xk and has a given angular coefficient m. It is easy to show that this choice produces the following algorithm

xk+1 = xk −

f (xk) m Clearly, not all choices of m will produce good results and one can easily find choices of m such that |xk+1 − x∗| > |xk − x∗|, i.e. the algorithm moves away from the root! We will come back to this shortly.

2.2.2. Newton’s method. Rather than using a fixed angular coefficient, whenever the function f (x) is differentiable one can actually use the derivative, thus producing an adaptive choice of the angular coefficient. This amounts to considering the tangent line to (xk, f (xk)), i.e. y = f (xk) + f ′(xk)(x − xk), so that

xk+1 = xk −

f (xk) f ′(xk)

f ′(xk) ̸= 0

2.2.3. Functional iteration methods and their convergence. Chords and Newton’s methods can in fact be seen as special cases of a general class of methods called functional iteration methods. The reason for introducing this general class is that it allows to study all methods at the same time. In particular, we will focus on convergence of the algorithms, i.e. whether they do reach the root they are looking for, and speed of convergence, i.e. how many iterations are needed to reach a given precision. The general idea of functional iteration methods is to replace the problem f (x) = 0 with the problem

(9) x = g(x)

with g(x) a continuous function, in such a way that the solutions of (9) are the roots of f (x). Solutions of (9) are also called fixed points of g(x). The iterative method is then defined through

(10) xk+1 = g(xk)

indeed, it is easy to prove that if the algorithm converges, then it converges to the solution of (9) and therefore to the root of f (x). This fact can be proved in one line. Let ζ = limk→∞ xk; then, because of the continuity of g(x) we have:

ζ = lim k→∞ xk+1 = lim k→∞ g(xk) = g( lim k→∞ xk) = g(ζ)

Of course, this result does not provide information on the actual convergence. It is just telling us that the method will not stop at the wrong point; but it could as well never stop. The following theorem provides conditions for convergence.

Theorem 2. Let x∗^ = g(x∗) and g ∈ C^1 (I) with I = [x∗^ − ρ, x∗^ + ρ] and ρ > 0 and such that |g′(x)| < 1 in I. Then, if x 0 ∈ I, we have limk→∞ xk = x∗.

2.2.4. Geometric interpretation of functional iteration methods. Solving the fixed point problem (9) corresponds to finding the intersection point between the graph of g(x) and the bisector of the first and third quadrant:

y = x y = g(x)

Solving the fixed point problem using the iterative algorithm (10) can be seen as starting from some x 1 , then finding to x 2 on the y axis through g(), then projecting back x 2 onto the x axis through the bisector, then finding x 3 on the y axis through g() again, and so on. It is easy to verify that:

  • if 0 ≤ g′(x) < 1 the sequence xkk=1,... is `e monotonic increasing if x 0 < x∗, and monotonic decreasing if x 0 > x∗
  • if − 1 < g′(x) ≤ 0 the sequence xkk=1,... is an alternating sequence of points on the left and points on the right of x∗. In this case, the solution is always contained between two subsequent values xk and xk+1, and |xk − xk+1| can be used as an estimate of the uncer- tainty/error.

2.2.5. Stopping criteria. A stopping criterion is needed to stop the iterations. Again, there are two common criteria, the choice depending on the application needs:

  • tolerance on the absolute/relative error: of course the error (i.e. |xk − x∗|) is not known in practice, as knowledge of the error corresponds to knowledge of the solution; however, one can use the difference between subsequent points as a “proxy” of the error; indeed, in addition to the already made observation that two subsequent iterations define an interval containing the solution if g′(x) ≤ 0, we can observe that, for g(x) ∈ C^1 [a, b]:

(xk − x∗) = g(xk− 1 ) − g(x∗) = g′(ξ)(xk− 1 − x∗) con |ξ − x∗| < |xk− 1 − x∗| xk − xk− 1 = (xk − x∗) − (xk− 1 − x∗) = (g′(ξ) − 1)(xk− 1 − x∗) and therefore |xk− 1 − x∗| =

|xk − xk− 1 | |g′(ξ) − 1 | so, in fact, the error is proportional to the difference between the iterations through the factor (^) |g′(ξ^1 )− 1 | (where ξ is an unknown point between xk and x∗). This fact also implies that when g′(x) is close to 1, the error can remain large even if the iterations get close.

  • tolerance on the function values: we can observe that f (xk) − f (x∗) = f (xk) = f ′(ξ)(xk − x∗) con |ξ − x∗| < |xk − x∗| and from this we get |xk − x∗| =

|f (xk)| |f ′(ξ)|

ϵf |f ′(ξ)| and therefore the absolute error can be large when f ′(ξ) is small. In particular, this might happen when f ′(x∗) = 0, i.e. x∗^ is a root with multiplicity larger than one.

2.2.6. Convergence speed. In order to quantify the convergence speed of an iterative algorithm, it is useful to introduce the concepts of order of convergence and rate of convergence. Definition. Let xk be a sequence that converges to x∗^ and such that xk ̸= x∗∀k. Now consider the limit (if it exists)

lim k→∞

|xk+1 − x∗| |xk − x∗|^1

= γ γ ≤ 1

We say that the convergence is linear if 0 < γ < 1, sublinear ife γ = 1, superlinear if γ = 0. In addition, if p > 1 exists such that

lim k→∞

|xk+1 − x∗| |xk − x∗|p^

= γ > 0 γ ∈ R

we say that the sequence has order of convergence p, and rate of convergence γ.

The following theorem links the order of convergence with the value of the derivative of g(x) in x∗:

Theorem 4. Let xk be a converging sequence to x∗, obtained by xk+1 = g(xk), with g ∈ C^1 [x∗^ − ρ, x∗^ + ρ], ρ > 0. If the convergence of xk is linear (sublinear, superlinear) then we have 0 < |g′(x∗)| < 1 (|g′(x∗)| = 1, |g′(x∗)| = 0).

Proof. □

Theorem 5. (viceversa of previous theorem) Let x∗^ be a fixed point of g(x):

  • if 0 < |g′(x∗)| < 1 =⇒ ∃ρ t.c. ∀x 0 : 0 < |x 0 − x∗| ≤ ρ then the sequence converges linearly.
  • if |g′(x∗)| = 1 and ∃ρ t.c. 0 < |g′(x)| < 1 for 0 < |x − x∗| < ρ =⇒ ∀x 0 s.t. 0 < |x 0 − x∗| ≤ ρ the sequence has sublinear convergence.

Proof. □

Theorem 6. Let x∗^ ∈ [a, b] be a fixed point of g(x), g(x) ∈ Cp[x∗^ − ρ, x∗^ − ρ] with p ≥ 2 integer, x 0 ∈ [x∗^ − ρ, x∗^ − ρ]; if the sequence xk converges with order p, then g′(x∗) = g′′(x∗) = · · · = g(p−1)(x∗) = 0, g(p)(x∗) ̸= 0

Proof. □

Theorem 7. (viceversa of previous theorem) Let x∗^ ∈ [a, b] be a fixed point of g(x), g(x) ∈ Cp[a, b] with p ≥ 2 integer. If g′(x∗) = g′′(x∗) = · · · = g(p−1)(x∗) = 0, g(p)(x∗) ̸= 0, there exists ρ such that ∀x 0 s.t. 0 < |x 0 − x∗| ≤ ρ, the sequence xk converges with order p.

Proof. □

with a method of order p = 1 we need

k 1 =

log δ log γ iterations; if use a method of order p > 1 we need

kp = logp

log

p−^ √ (^1) γ|e 0 |δ

log

p−^ √ (^1) γ|e 0 |

in conclusion, if we use a method of order p, the number of iterations to reach a given accuracy is the logarithm of the number of iterations needed by a method of order 1.

Of course, it is important to remark that in practical applications the number of iterations is not the only responsible of the computational efficiency of a method. For instance, Newton’s method converges with order 2 (when the root has multiplicity 1), which is better than the chords method, but it requires the calculation of the derivative, which might be computationally challenging/heavy; in practice then, the theoretical advantage of Newton’s method might be smaller than expected. Other methods might require the calculation of the function f (x) in several points, rather than just one, and this also might contribute to reduce the computational efficiency of apparently performant methods. In conclusion, the actual effectiveness must be evaluated on a case-by-case manner.

  1. Gradient methods We now consider the problem of finding the minimum of a real-valued function f (x) with x ∈ Rn. We first recall few basic concepts related to the analysis for functions in Rn. The level set of a function is the set of points x ∈ Rn^ such that f (x) = k, where k is a generic constant: changing k we change the level set; topographic elevation maps are a common example of level sets, where each line (level set) contains all points with the same elevation. The gradient of the function f (x) at the point x 0 is the vector whose components are the partial derivatives of f (x):

∇f (x 0 ) =

∂f ∂x (^1) x=x 0

∂f ∂x (^2) x=x 0

∂f ∂xn (^) x=x 0

An extremely important property of the gradient is that it is always orthogonal (unless it is null) to the level set curve, or, more precisely, to the tangent line to the level set curve. The importance of this fact lies in the fact that the gradient is the direction of maximum rate of increase of f. It is important to remark how this is a local property: starting from x 0 and moving a small bit in the direction of ∇f (x 0 ) one is guaranteed to go “upwards”; however, as soon as one moves to x ̸= x 0 the direction of the gradient might as well change. However, if one is aiming at minimizing the function f , it appears to be a good idea, in some sense the best idea, to move against the gradient. This idea is indeed at the basis of so-called gradient methods, i.e. iterative algorithms for function minimization that generate the next point by moving against the gradient

xk+1 = xk − αk∇f (xk)

where αk > 0 is the step size, possibly (usually) changing at every iteration.

3.1. Steepest Descent.. The method of steepest descent is a gradient algorithm where, at each iteration, the step size αk is chosen so as to reach the minimum of the function in the direction of the gradient. Formally, one can define

ϕk(α) = f (xk − α∇f (xk))

and then

(15) αk = arg min α≥ 0 ϕk(α)

In general, this minimization will be accomplished through a so-called line search.

3.1.1. Fundamental properties of steepest descent. As a consequence of choice (15), in the steepest descent each search direction is orthogonal to the previous one:

Theorem 9. Given a sequence {xk}k=1,... constructed by the steepest descent algorithm for a function f : Rn^ → R, the vector xk+1 − xk is orthogonal to the vector xk+2 − xk+