Skip to main content

Chapter 2 · 6 hours

Solutions of linear equations

IOE past exam questions

Past questions and answers

17 questions set from this chapter, 1 of them more than once. Most repeated first.

  • Asked 2 times
  • 2079 Shrawan · 5 marks
  • 2071 Bhadra · 3 marks

Explain the conjugate gradient method and its algorithm for solving a system of linear equations.

Answer

Conjugate gradient method

The conjugate gradient (CG) method solves Ax=bAx = b for a symmetric, positive definite matrix AA. It is equivalent to minimising the quadratic energy

Π(x)=12xTAx−bTx\Pi(x) = \tfrac{1}{2}x^T A x - b^T x

whose minimum is exactly the solution of Ax=bAx=b. The minimum is searched along directions dkd_k that are A-conjugate, i.e. diTAdj=0d_i^T A d_j = 0 for i≠ji \ne j. Each step minimises Π\Pi along one direction without spoiling the earlier ones, so in exact arithmetic the solution is reached in at most nn steps for an n×nn \times n system. The residual r=b−Axr = b - Ax is the negative gradient of Π\Pi.

Compared with direct elimination, CG needs only matrix-vector products, so it stores only the non-zero terms of AA. It is good for large sparse systems, and rounding errors do not accumulate in a long elimination.

Algorithm

  1. Choose a starting vector x0x_0 (usually 00). Compute the residual r0=b−Ax0r_0 = b - Ax_0 and set the first search direction d0=r0d_0 = r_0.
  2. For k=0,1,2,…k = 0, 1, 2, \dots repeat:
    • Step length: αk=rkTrkdkTAdk\alpha_k = \dfrac{r_k^T r_k}{d_k^T A d_k}
    • Update the solution: xk+1=xk+αkdkx_{k+1} = x_k + \alpha_k d_k
    • Update the residual: rk+1=rk−αkAdkr_{k+1} = r_k - \alpha_k A d_k
    • Check convergence: stop if ∥rk+1∥<\|r_{k+1}\| < tolerance.
    • Direction factor: βk=rk+1Trk+1rkTrk\beta_k = \dfrac{r_{k+1}^T r_{k+1}}{r_k^T r_k}
    • New direction: dk+1=rk+1+βkdkd_{k+1} = r_{k+1} + \beta_k d_k
  3. The last xk+1x_{k+1} is the solution.

Convergence is faster if AA has clustered eigenvalues, and preconditioning is used to improve this.

  • 2078 Chaitra · 5 marks

Solve the given system of equations using the conjugate gradient method.
2x1−x2=42x_1 - x_2 = 4
−x1+2x2−x3=0-x_1 + 2x_2 - x_3 = 0
−x2+2x3=0-x_2 + 2x_3 = 0

Similar questions: Conjugate gradient numerical (3,0,2 system) (2071 Bhadra)

Answer

Matrix form: A=[2−10−12−10−12]A=\begin{bmatrix}2&-1&0\\-1&2&-1\\0&-1&2\end{bmatrix}, b={4,0,0}Tb=\{4,0,0\}^T. AA is symmetric and positive definite. Start with x0={0,0,0}Tx_0=\{0,0,0\}^T.

r0=b−Ax0={4,0,0}Tr_0=b-Ax_0=\{4,0,0\}^T, d0=r0d_0=r_0.

Iteration 1

Ad0={8,−4,0}Tα0=r0Tr0d0TAd0=1632=0.5x1={2,0,0}Tr1=r0−α0Ad0={0,2,0}Tβ0=416=0.25,d1=r1+β0d0={1,2,0}T\begin{aligned} Ad_0&=\{8,-4,0\}^T\\ \alpha_0&=\frac{r_0^Tr_0}{d_0^TAd_0}=\frac{16}{32}=0.5\\ x_1&=\{2,0,0\}^T\\ r_1&=r_0-\alpha_0Ad_0=\{0,2,0\}^T\\ \beta_0&=\frac{4}{16}=0.25,\quad d_1=r_1+\beta_0d_0=\{1,2,0\}^T \end{aligned}

Iteration 2

Ad1={0,3,−2}Tα1=46=0.6667x2={2.6667, 1.3333, 0}Tr2={0,0,1.3333}Tβ1=1.77784=0.4444,d2={0.4444, 0.8889, 1.3333}T\begin{aligned} Ad_1&=\{0,3,-2\}^T\\ \alpha_1&=\frac{4}{6}=0.6667\\ x_2&=\{2.6667,\,1.3333,\,0\}^T\\ r_2&=\{0,0,1.3333\}^T\\ \beta_1&=\frac{1.7778}{4}=0.4444,\quad d_2=\{0.4444,\,0.8889,\,1.3333\}^T \end{aligned}

Iteration 3

Ad2={0,0,1.7778}Tα2=1.77782.3704=0.75x3={3, 2, 1}Tr3={0,0,0}T\begin{aligned} Ad_2&=\{0,0,1.7778\}^T\\ \alpha_2&=\frac{1.7778}{2.3704}=0.75\\ x_3&=\{3,\,2,\,1\}^T\\ r_3&=\{0,0,0\}^T \end{aligned}

The residual is zero after n=3n=3 iterations, as expected for CG.

Answer: x1=3, x2=2, x3=1x_1=3,\ x_2=2,\ x_3=1. (Check: 2(3)−2=42(3)-2=4, −3+4−1=0-3+4-1=0, −2+2=0-2+2=0.)

  • 2071 Bhadra · 5 marks

Solve the given system of equations using the conjugate gradient method.
[302011213]{x1x2x3}={10−1}\begin{bmatrix} 3 & 0 & 2 \\ 0 & 1 & 1 \\ 2 & 1 & 3 \end{bmatrix}\begin{Bmatrix} x_1 \\ x_2 \\ x_3 \end{Bmatrix} = \begin{Bmatrix} 1 \\ 0 \\ -1 \end{Bmatrix}

Similar questions: Conjugate gradient numerical (2,-1 system) (2078 Chaitra)

Answer

A=[302011213]A=\begin{bmatrix}3&0&2\\0&1&1\\2&1&3\end{bmatrix} is symmetric and positive definite (leading minors 3, 3, 4>03,\ 3,\ 4>0). b={1,0,−1}Tb=\{1,0,-1\}^T. Take x0=0x_0=0: r0=br_0=b, d0=r0={1,0,−1}Td_0=r_0=\{1,0,-1\}^T.

Iteration 1

Ad0={1, −1, −1}Tα0=r0Tr0d0TAd0=22=1x1={1, 0, −1}Tr1=r0−α0Ad0={0, 1, 0}Tβ0=12=0.5,d1=r1+β0d0={0.5, 1, −0.5}T\begin{aligned} Ad_0&=\{1,\,-1,\,-1\}^T\\ \alpha_0&=\frac{r_0^Tr_0}{d_0^TAd_0}=\frac{2}{2}=1\\ x_1&=\{1,\,0,\,-1\}^T\\ r_1&=r_0-\alpha_0Ad_0=\{0,\,1,\,0\}^T\\ \beta_0&=\frac{1}{2}=0.5,\quad d_1=r_1+\beta_0d_0=\{0.5,\,1,\,-0.5\}^T \end{aligned}

Iteration 2

Ad1={0.5, 0.5, 0.5}Tα1=10.5=2x2={2, 2, −2}Tr2={−1, 0, −1}Tβ1=21=2,d2={0, 2, −2}T\begin{aligned} Ad_1&=\{0.5,\,0.5,\,0.5\}^T\\ \alpha_1&=\frac{1}{0.5}=2\\ x_2&=\{2,\,2,\,-2\}^T\\ r_2&=\{-1,\,0,\,-1\}^T\\ \beta_1&=\frac{2}{1}=2,\quad d_2=\{0,\,2,\,-2\}^T \end{aligned}

Iteration 3

Ad2={−4, 0, −4}Tα2=28=0.25x3={2, 2.5, −2.5}Tr3={0, 0, 0}T\begin{aligned} Ad_2&=\{-4,\,0,\,-4\}^T\\ \alpha_2&=\frac{2}{8}=0.25\\ x_3&=\{2,\,2.5,\,-2.5\}^T\\ r_3&=\{0,\,0,\,0\}^T \end{aligned}

Answer: x1=2, x2=2.5, x3=−2.5x_1=2,\ x_2=2.5,\ x_3=-2.5. Check: 3(2)+2(−2.5)=13(2)+2(-2.5)=1, 2.5−2.5=02.5-2.5=0, 2(2)+2.5−7.5=−12(2)+2.5-7.5=-1.

  • 2079 Jestha · 8 marks

Explain the solution methods of solving a system of linear equations with examples.

Answer

A system [A]{x}={b}[A]\{x\}=\{b\} is solved by direct or iterative methods.

Direct methods

They give the exact answer (apart from round-off) after a fixed number of operations.

  • Gauss elimination: reduce AA to upper triangular form, then back-substitute.
  • LU decomposition / Cholesky (A=LLTA=LL^T for symmetric positive definite matrices): factor once, then solve for several right-hand sides.
  • Gauss-Jordan and matrix inverse.

Example: 2x+y=5, x+3y=102x+y=5,\ x+3y=10. Eliminating, R2→R2−12R1R_2\to R_2-\tfrac12R_1 gives 2.5y=7.52.5y=7.5, so y=3y=3, x=1x=1.

Iterative methods

Start from a guess and improve it until the change is small. They suit large sparse systems.

  • Jacobi: xi(k+1)=1aii(bi−∑j≠iaijxj(k))x_i^{(k+1)}=\dfrac{1}{a_{ii}}\Big(b_i-\sum_{j\ne i}a_{ij}x_j^{(k)}\Big)
  • Gauss-Seidel: same but uses new values immediately.
  • SOR: Gauss-Seidel with relaxation factor ω\omega.
  • Conjugate gradient: minimises 12xTAx−bTx\tfrac12x^TAx-b^Tx for symmetric positive definite AA.

Example (Gauss-Seidel): 4x+y=9, x+3y=74x+y=9,\ x+3y=7, start (0,0)(0,0).

  • Iteration 1: x=9/4=2.25x=9/4=2.25, y=(7−2.25)/3=1.583y=(7-2.25)/3=1.583.
  • Iteration 2: x=(9−1.583)/4=1.854x=(9-1.583)/4=1.854, y=(7−1.854)/3=1.715y=(7-1.854)/3=1.715.

The values move to the exact solution x=20/11=1.818x=20/11=1.818, y=19/11=1.727y=19/11=1.727.

Comparison

DirectIterative
Fixed operations, exactApproximate, needs convergence
Fill-in destroys sparsityKeeps sparsity, low memory
Best for small/medium systemsBest for very large sparse systems
  • 2079 Shrawan · 3 marks

What do you mean by sparse matrix, banded matrix and memory optimization?

Answer

Sparse matrix: a matrix in which most entries are zero. Stiffness matrices of FEM are sparse because a node is connected only to the nodes of neighbouring elements.

Banded matrix: a matrix whose non-zero entries lie in a narrow band about the main diagonal, i.e. aij=0a_{ij}=0 for ∣i−j∣>b|i-j|>b. The half-bandwidth is

b=(max difference of node numbers in an element+1)×dof per nodeb=(\text{max difference of node numbers in an element}+1)\times \text{dof per node}

A symmetric matrix of order nn and half-bandwidth bb is stored with only n×bn\times b numbers instead of n2n^2.

 x x . . .
 x x x . .      band along the
 . x x x .      diagonal, zeros
 . . x x x      outside
 . . . x x

Memory optimisation: reducing the memory needed to store and solve [K]{U}={F}[K]\{U\}=\{F\}. Techniques are:

  • store only the upper triangle (symmetry);
  • store only the band (banded storage) or the skyline profile;
  • store only non-zero terms with index arrays (sparse storage);
  • renumber nodes to minimise bandwidth. Less memory also gives fewer operations: the cost of banded elimination is about nb2n b^2 instead of n3n^3.
  • 2078 Chaitra · 3 marks

Briefly explain the different iterative methods used for the solution of a given set of equations.

Answer

Iterative methods start from an assumed solution and improve it repeatedly until the change is within tolerance. They are used for large sparse systems [A]{x}={b}[A]\{x\}=\{b\} and need diagonal dominance (or symmetry and positive definiteness) for convergence.

  1. Jacobi method: every unknown is computed using values of the previous iteration only.
xi(k+1)=1aii(bi−∑j≠iaijxj(k))x_i^{(k+1)}=\frac{1}{a_{ii}}\Big(b_i-\sum_{j\ne i}a_{ij}x_j^{(k)}\Big)
  1. Gauss-Seidel method: newly computed values are used immediately in the same iteration:
xi(k+1)=1aii(bi−∑j<iaijxj(k+1)−∑j>iaijxj(k))x_i^{(k+1)}=\frac{1}{a_{ii}}\Big(b_i-\sum_{j<i}a_{ij}x_j^{(k+1)}-\sum_{j>i}a_{ij}x_j^{(k)}\Big)

It converges about twice as fast as Jacobi. 3. Successive over-relaxation (SOR): xinew=(1−ω)xiold+ω xiGSx_i^{new}=(1-\omega)x_i^{old}+\omega\,x_i^{GS} with 1<ω<21<\omega<2 to speed up convergence. 4. Conjugate gradient method: for symmetric positive definite matrices; minimises the quadratic energy along conjugate directions and converges in at most nn steps.

  • 2078 Kartik · 2+6 marks

What are the direct methods and iterative methods of solving linear equations? Solve the following set of linear equations by the Gauss-Seidel method starting with initial guess of [1,2,3][1, 2, 3].
12x+3y−5z=112x + 3y - 5z = 1
x+5y+3z=28x + 5y + 3z = 28
3x+7y+13z=763x + 7y + 13z = 76

Answer

Direct and iterative methods

  • Direct methods give the solution in a finite, known number of operations (exact apart from round-off). Examples: Gauss elimination, Gauss-Jordan, LU and Cholesky decomposition, matrix inverse (Cramer's rule). They are best for small or dense systems.
  • Iterative methods start from a trial vector and improve it repeatedly until the change is below a tolerance. Examples: Jacobi, Gauss-Seidel, SOR, conjugate gradient. They are best for large sparse systems and need convergence conditions such as diagonal dominance.

Gauss-Seidel solution

The system is diagonally dominant (12>812>8, 5>45>4, 13>1013>10), so it converges. Rearranging:

x=1−3y+5z12,y=28−x−3z5,z=76−3x−7y13x=\frac{1-3y+5z}{12},\quad y=\frac{28-x-3z}{5},\quad z=\frac{76-3x-7y}{13}

Start (x,y,z)=(1,2,3)(x,y,z)=(1,2,3).

Iterationxxyyzz
10.83333.63333.6974
20.71563.23843.9373
30.91433.05483.9903
40.98233.00943.9990
50.99733.00114.0000
60.99973.00004.0000

Example of iteration 1: x=(1−3(2)+5(3))/12=0.8333x=(1-3(2)+5(3))/12=0.8333; y=(28−0.8333−9)/5=3.6333y=(28-0.8333-9)/5=3.6333; z=(76−2.5−25.4333)/13=3.6974z=(76-2.5-25.4333)/13=3.6974.

Answer: x≈1, y≈3, z≈4x\approx1,\ y\approx3,\ z\approx4 (exact solution x=1,y=3,z=4x=1,y=3,z=4).

  • 2077 Chaitra · 3 marks

Explain with relevant examples how banded matrix and skyline storage scheme optimize the memory.

Answer

In FEM the stiffness matrix [K][K] is symmetric, sparse and has non-zero terms only near the diagonal. Storing the full n×nn\times n matrix wastes memory.

Banded storage

Only the band is stored: the diagonal and the b−1b-1 upper terms of each row (using symmetry). Half-bandwidth b=(max node difference in an element+1)×b=(\text{max node difference in an element}+1)\times dof per node.

Example: a bar of 100 nodes (1 dof), elements connect nodes ii and i+1i+1, so b=2b=2. Full storage =1002=10000=100^2=10000 numbers; banded storage =100×2=200=100\times2=200 numbers.

 Full 5x5 (symmetric)        Banded (b=2)
 a11 a12  0   0   0          a11 a12
 a12 a22 a23  0   0          a22 a23
  0  a23 a33 a34  0   ->     a33 a34
  0   0  a34 a44 a45         a44 a45
  0   0   0  a45 a55         a55  *

Skyline (variable band / profile) storage

Each column is stored from the first non-zero entry down to the diagonal, so the band height varies with column. A pointer array stores the diagonal positions.

Example: column heights 1, 2, 2, 3, 1 give 9 stored terms against 15 for the full upper triangle of a 5×55\times5 matrix.

Skyline storage stores fewer terms than a constant band when a few nodes have a large connectivity. Fill-in during elimination remains inside the skyline, so the factorisation also needs no extra storage. Node renumbering (e.g. reverse Cuthill-McKee) reduces the bandwidth and so the memory and operation count.

  • 2077 Chaitra · 3+2 marks

Write down the algorithm for solving a set of linear equations by the conjugate gradient method and its limitations.

Answer

Algorithm

  1. Choose a starting vector x0x_0 (usually 00). Compute the residual r0=b−Ax0r_0 = b - Ax_0 and set the first search direction d0=r0d_0 = r_0.
  2. For k=0,1,2,…k = 0, 1, 2, \dots repeat:
    • Step length: αk=rkTrkdkTAdk\alpha_k = \dfrac{r_k^T r_k}{d_k^T A d_k}
    • Update the solution: xk+1=xk+αkdkx_{k+1} = x_k + \alpha_k d_k
    • Update the residual: rk+1=rk−αkAdkr_{k+1} = r_k - \alpha_k A d_k
    • Check convergence: stop if ∥rk+1∥<\|r_{k+1}\| < tolerance.
    • Direction factor: βk=rk+1Trk+1rkTrk\beta_k = \dfrac{r_{k+1}^T r_{k+1}}{r_k^T r_k}
    • New direction: dk+1=rk+1+βkdkd_{k+1} = r_{k+1} + \beta_k d_k
  3. The last xk+1x_{k+1} is the solution.

Limitations

  • Applies only to symmetric, positive definite matrices (not to general or indefinite systems without modification).
  • Convergence slows for ill-conditioned matrices (large ratio of largest to smallest eigenvalue), so preconditioning is often needed.
  • Round-off errors destroy the conjugacy of the directions, so more than nn iterations may be required in practice.
  • Gives one right-hand side at a time; a direct (factored) solver is more efficient for many load cases.
  • Needs a good stopping criterion; residual may fall while the error is still large.
  • 2075 Bhadra · 3+5 marks

Explain different solution techniques of linear equations. For the given linear system
[12−60−612−60−66]{x1x2x3}={24240}\begin{bmatrix} 12 & -6 & 0 \\ -6 & 12 & -6 \\ 0 & -6 & 6 \end{bmatrix}\begin{Bmatrix} x_1 \\ x_2 \\ x_3 \end{Bmatrix} = \begin{Bmatrix} 24 \\ 24 \\ 0 \end{Bmatrix} using the starting vector x(0)=(4,4,0)Tx^{(0)} = (4, 4, 0)^T, carry out two iterations of the conjugate gradient method and show the result.

Answer

Linear system [A]{x}={b}[A]\{x\}=\{b\} is solved by:

  1. Direct methods (finite number of steps, exact apart from round-off): Gauss elimination (reduce to upper triangular form, back-substitute), Gauss-Jordan, LU decomposition, Cholesky decomposition A=LLTA=LL^T for symmetric positive definite AA, and the matrix inverse. In FEM they use banded or skyline storage.
  2. Iterative methods (start from a guess and improve): Jacobi, Gauss-Seidel, successive over-relaxation, and the conjugate gradient method. They suit very large sparse systems since the matrix is never changed and no fill-in occurs. Jacobi and Gauss-Seidel need diagonal dominance for convergence; CG needs a symmetric positive definite matrix.
DirectIterative
Fixed operation countNumber of iterations depends on tolerance
Fill-in within band/skylineKeeps sparsity
Good for many load cases (factor once)Good for very large systems

Conjugate gradient, two iterations

A=[12−60−612−60−66]A=\begin{bmatrix}12&-6&0\\-6&12&-6\\0&-6&6\end{bmatrix}, b={24,24,0}Tb=\{24,24,0\}^T, x0={4,4,0}Tx_0=\{4,4,0\}^T.

Ax0={12(4)−6(4), −6(4)+12(4), −6(4)}={24,24,−24}TAx_0=\{12(4)-6(4),\,-6(4)+12(4),\,-6(4)\}=\{24,24,-24\}^T, so

r0=b−Ax0={0,0,24}T,d0=r0r_0=b-Ax_0=\{0,0,24\}^T,\quad d_0=r_0

Iteration 1

Ad0={0,−144,144}Tα0=r0Tr0d0TAd0=5763456=0.1667x1=x0+α0d0={4, 4, 4}Tr1=r0−α0Ad0={0, 24, 0}Tβ0=576576=1,d1=r1+β0d0={0, 24, 24}T\begin{aligned} Ad_0&=\{0,-144,144\}^T\\ \alpha_0&=\frac{r_0^Tr_0}{d_0^TAd_0}=\frac{576}{3456}=0.1667\\ x_1&=x_0+\alpha_0d_0=\{4,\,4,\,4\}^T\\ r_1&=r_0-\alpha_0Ad_0=\{0,\,24,\,0\}^T\\ \beta_0&=\frac{576}{576}=1,\quad d_1=r_1+\beta_0d_0=\{0,\,24,\,24\}^T \end{aligned}

Iteration 2

Ad1={−144, 144, 0}Tα1=5763456=0.1667x2=x1+α1d1={4, 8, 8}Tr2=r1−α1Ad1={24, 0, 0}T\begin{aligned} Ad_1&=\{-144,\,144,\,0\}^T\\ \alpha_1&=\frac{576}{3456}=0.1667\\ x_2&=x_1+\alpha_1d_1=\{4,\,8,\,8\}^T\\ r_2&=r_1-\alpha_1Ad_1=\{24,\,0,\,0\}^T \end{aligned}

Answer: after two iterations x(2)={4, 8, 8}Tx^{(2)}=\{4,\,8,\,8\}^T with residual {24,0,0}T\{24,0,0\}^T. A third iteration gives the exact solution x={8,12,12}Tx=\{8,12,12\}^T (the system has n=3n=3 unknowns).

  • 2074 Bhadra · 4 marks

Describe briefly the Discrete Fourier Transform (DFT) and the Fast Fourier Transform (FFT).

Answer

Discrete Fourier Transform (DFT)

The DFT converts NN equally spaced samples xnx_n of a signal in the time domain into NN complex frequency components XkX_k:

Xk=∑n=0N−1xn e−i2πkn/N,k=0,…,N−1X_k=\sum_{n=0}^{N-1}x_n\,e^{-i2\pi kn/N},\quad k=0,\dots,N-1

and the inverse is

xn=1N∑k=0N−1Xk ei2πkn/Nx_n=\frac{1}{N}\sum_{k=0}^{N-1}X_k\,e^{i2\pi kn/N}

∣Xk∣|X_k| gives the amplitude and arg⁡Xk\arg X_k the phase of the component at frequency fk=k/(NΔt)f_k=k/(N\Delta t). Direct evaluation needs N2N^2 complex multiplications.

Fast Fourier Transform (FFT)

The FFT (Cooley and Tukey, 1965) is an efficient algorithm for computing the DFT. It splits the sum into even- and odd-numbered samples repeatedly (for N=2mN=2^m):

Xk=Ek+WNk Ok,Xk+N/2=Ek−WNk Ok,WN=e−i2π/NX_k=E_k+W_N^{k}\,O_k,\qquad X_{k+N/2}=E_k-W_N^{k}\,O_k,\qquad W_N=e^{-i2\pi/N}

This "butterfly" operation reduces the work to N2log⁡2N\tfrac{N}{2}\log_2N multiplications, so N=1024N=1024 needs about 5,000 operations instead of 10^6.

Uses in civil engineering: frequency content of earthquake records, vibration of bridges and buildings, spectral analysis of waves, signal filtering.

  • 2074 Bhadra · 4 marks

Carry out three iterations of the conjugate gradient method for the following system of linear equations:
[10−60−68−20−25]{x1x2x3}={1200}\begin{bmatrix} 10 & -6 & 0 \\ -6 & 8 & -2 \\ 0 & -2 & 5 \end{bmatrix}\begin{Bmatrix} x_1 \\ x_2 \\ x_3 \end{Bmatrix} = \begin{Bmatrix} 12 \\ 0 \\ 0 \end{Bmatrix}

Answer

A=[10−60−68−20−25]A=\begin{bmatrix}10&-6&0\\-6&8&-2\\0&-2&5\end{bmatrix} (symmetric, positive definite), b={12,0,0}Tb=\{12,0,0\}^T. Take x0={0,0,0}Tx_0=\{0,0,0\}^T, so r0=b={12,0,0}Tr_0=b=\{12,0,0\}^T, d0=r0d_0=r_0.

Iteration 1

Ad0={120,−72,0}Tα0=1441440=0.1x1={1.2, 0, 0}Tr1={0, 7.2, 0}Tβ0=51.84144=0.36,d1={4.32, 7.2, 0}T\begin{aligned} Ad_0&=\{120,-72,0\}^T\\ \alpha_0&=\frac{144}{1440}=0.1\\ x_1&=\{1.2,\,0,\,0\}^T\\ r_1&=\{0,\,7.2,\,0\}^T\\ \beta_0&=\frac{51.84}{144}=0.36,\quad d_1=\{4.32,\,7.2,\,0\}^T \end{aligned}

Iteration 2

Ad1={0, 31.68, −14.4}Tα1=51.84228.10=0.22727x2={2.1818, 1.6364, 0}Tr2={0, 0, 3.2727}Tβ1=10.710751.84=0.20661,d2={0.8926, 1.4876, 3.2727}T\begin{aligned} Ad_1&=\{0,\,31.68,\,-14.4\}^T\\ \alpha_1&=\frac{51.84}{228.10}=0.22727\\ x_2&=\{2.1818,\,1.6364,\,0\}^T\\ r_2&=\{0,\,0,\,3.2727\}^T\\ \beta_1&=\frac{10.7107}{51.84}=0.20661,\quad d_2=\{0.8926,\,1.4876,\,3.2727\}^T \end{aligned}

Iteration 3

Ad2={0, 0, 13.388}Tα2=10.710743.815=0.24444x3={2.4, 2.0, 0.8}Tr3={0, 0, 0}T\begin{aligned} Ad_2&=\{0,\,0,\,13.388\}^T\\ \alpha_2&=\frac{10.7107}{43.815}=0.24444\\ x_3&=\{2.4,\,2.0,\,0.8\}^T\\ r_3&=\{0,\,0,\,0\}^T \end{aligned}
Iterationx1x_1x2x_2x3x_3∥r∥\|r\|
000012
11.2000007.2
22.18181.636403.273
32.40002.00000.80000

Answer: x1=2.4, x2=2.0, x3=0.8x_1=2.4,\ x_2=2.0,\ x_3=0.8. Check: 10(2.4)−6(2)=1210(2.4)-6(2)=12, −6(2.4)+8(2)−2(0.8)=0-6(2.4)+8(2)-2(0.8)=0, −2(2)+5(0.8)=0-2(2)+5(0.8)=0.

  • 2073 Magh · 4+4 marks

Write down the algorithm for the conjugate gradient method. Consider the system
[2−1016−24−38]{x1x2x3}={2−45}\begin{bmatrix} 2 & -1 & 0 \\ 1 & 6 & -2 \\ 4 & -3 & 8 \end{bmatrix}\begin{Bmatrix} x_1 \\ x_2 \\ x_3 \end{Bmatrix} = \begin{Bmatrix} 2 \\ -4 \\ 5 \end{Bmatrix} Solve the above system by using Gauss-Seidel iteration starting with x(0)=(0,0,0)Tx^{(0)} = (0, 0, 0)^T.

Answer

Algorithm for the conjugate gradient method

  1. Choose a starting vector x0x_0 (usually 00). Compute the residual r0=b−Ax0r_0 = b - Ax_0 and set the first search direction d0=r0d_0 = r_0.
  2. For k=0,1,2,…k = 0, 1, 2, \dots repeat:
    • Step length: αk=rkTrkdkTAdk\alpha_k = \dfrac{r_k^T r_k}{d_k^T A d_k}
    • Update the solution: xk+1=xk+αkdkx_{k+1} = x_k + \alpha_k d_k
    • Update the residual: rk+1=rk−αkAdkr_{k+1} = r_k - \alpha_k A d_k
    • Check convergence: stop if ∥rk+1∥<\|r_{k+1}\| < tolerance.
    • Direction factor: βk=rk+1Trk+1rkTrk\beta_k = \dfrac{r_{k+1}^T r_{k+1}}{r_k^T r_k}
    • New direction: dk+1=rk+1+βkdkd_{k+1} = r_{k+1} + \beta_k d_k
  3. The last xk+1x_{k+1} is the solution.

The method needs a symmetric positive definite matrix and gives the exact solution in at most nn steps.

Gauss-Seidel solution

The matrix is diagonally dominant (2>12>1, 6>36>3, 8>78>7), so Gauss-Seidel converges. Rewrite the equations:

x1=2+x22,x2=−4−x1+2x36,x3=5−4x1+3x28x_1=\frac{2+x_2}{2},\qquad x_2=\frac{-4-x_1+2x_3}{6},\qquad x_3=\frac{5-4x_1+3x_2}{8}

Start with x(0)=(0,0,0)x^{(0)}=(0,0,0) and use the newest values at once.

Iterationx1x_1x2x_2x3x_3
11.0000-0.8333-0.1875
20.5833-0.82640.0234
30.5868-0.75670.0479
40.6217-0.75430.0313
50.6228-0.76000.0286
60.6200-0.76050.0298
70.6198-0.76000.0301
80.6200-0.76000.0300

Example of iteration 1: x1=(2+0)/2=1x_1=(2+0)/2=1; x2=(−4−1+0)/6=−0.8333x_2=(-4-1+0)/6=-0.8333; x3=(5−4+3(−0.8333))/8=−0.1875x_3=(5-4+3(-0.8333))/8=-0.1875.

Answer: x1≈0.62, x2≈−0.76, x3≈0.03x_1\approx0.62,\ x_2\approx-0.76,\ x_3\approx0.03.

  • 2072 Asoj · 5+3 marks

Explain different solution techniques of linear equations. Write the algorithm for the conjugate gradient method.

Answer

Linear system [A]{x}={b}[A]\{x\}=\{b\} is solved by:

  1. Direct methods (finite number of steps, exact apart from round-off): Gauss elimination (reduce to upper triangular form, back-substitute), Gauss-Jordan, LU decomposition, Cholesky decomposition A=LLTA=LL^T for symmetric positive definite AA, and the matrix inverse. In FEM they use banded or skyline storage.
  2. Iterative methods (start from a guess and improve): Jacobi, Gauss-Seidel, successive over-relaxation, and the conjugate gradient method. They suit very large sparse systems since the matrix is never changed and no fill-in occurs. Jacobi and Gauss-Seidel need diagonal dominance for convergence; CG needs a symmetric positive definite matrix.
DirectIterative
Fixed operation countNumber of iterations depends on tolerance
Fill-in within band/skylineKeeps sparsity
Good for many load cases (factor once)Good for very large systems

Algorithm of the conjugate gradient method

The conjugate gradient (CG) method solves Ax=bAx = b for a symmetric, positive definite matrix AA. It is equivalent to minimising the quadratic energy

Π(x)=12xTAx−bTx\Pi(x) = \tfrac{1}{2}x^T A x - b^T x

whose minimum is exactly the solution of Ax=bAx=b. The minimum is searched along directions dkd_k that are A-conjugate, i.e. diTAdj=0d_i^T A d_j = 0 for i≠ji \ne j. Each step minimises Π\Pi along one direction without spoiling the earlier ones, so in exact arithmetic the solution is reached in at most nn steps for an n×nn \times n system. The residual r=b−Axr = b - Ax is the negative gradient of Π\Pi.

  1. Choose a starting vector x0x_0 (usually 00). Compute the residual r0=b−Ax0r_0 = b - Ax_0 and set the first search direction d0=r0d_0 = r_0.
  2. For k=0,1,2,…k = 0, 1, 2, \dots repeat:
    • Step length: αk=rkTrkdkTAdk\alpha_k = \dfrac{r_k^T r_k}{d_k^T A d_k}
    • Update the solution: xk+1=xk+αkdkx_{k+1} = x_k + \alpha_k d_k
    • Update the residual: rk+1=rk−αkAdkr_{k+1} = r_k - \alpha_k A d_k
    • Check convergence: stop if ∥rk+1∥<\|r_{k+1}\| < tolerance.
    • Direction factor: βk=rk+1Trk+1rkTrk\beta_k = \dfrac{r_{k+1}^T r_{k+1}}{r_k^T r_k}
    • New direction: dk+1=rk+1+βkdkd_{k+1} = r_{k+1} + \beta_k d_k
  3. The last xk+1x_{k+1} is the solution.
  • 2070 Bhadra · 4 marks

Why is the conjugate gradient method used in computation over Gaussian methods?

Answer

Gaussian elimination is a direct method that reduces [A][A] to triangular form, while the conjugate gradient (CG) method is an iterative method that minimises 12xTAx−bTx\tfrac12x^TAx-b^Tx along A-conjugate directions. CG is preferred for large problems for these reasons:

  1. Memory: CG needs only matrix-vector products AdAd, so only the non-zero terms of the sparse matrix are stored. Gaussian elimination produces fill-in, which destroys sparsity inside the band.
  2. Operation count: each CG iteration costs about n×(non-zeros per row)n\times(\text{non-zeros per row}) operations, and a good solution often comes in far fewer than nn iterations, whereas elimination costs about n3/3n^3/3 (or nb2nb^2 for a banded matrix).
  3. Accuracy: round-off errors in elimination accumulate over nn steps; in CG each iteration uses the original matrix and corrects the error.
  4. Flexibility: the solution can be stopped when the residual is small enough, and a good starting guess can be used; elimination cannot be stopped early.
  5. Parallelism: matrix-vector products are easy to parallelise, and the matrix need not even be assembled (element-by-element products).
  6. In exact arithmetic CG finishes in at most nn steps and with preconditioning converges faster.

Limitation: CG is applicable only to symmetric positive definite matrices, and for several load vectors a factorised direct solver may be cheaper.

  • 2070 Bhadra · 8 marks

Solve the following equation by using the conjugate gradient method (maximum 5 iterations).
[3010−13130]{x1x2x3}={1−122}\begin{bmatrix} 3 & 0 & 1 \\ 0 & -1 & 3 \\ 1 & 3 & 0 \end{bmatrix}\begin{Bmatrix} x_1 \\ x_2 \\ x_3 \end{Bmatrix} = \begin{Bmatrix} 1 \\ -12 \\ 2 \end{Bmatrix}

Answer

A=[3010−13130]A=\begin{bmatrix}3&0&1\\0&-1&3\\1&3&0\end{bmatrix}, b={1,−12,2}Tb=\{1,-12,2\}^T. AA is symmetric (but not positive definite, as its eigenvalues are 3.61, 2, −3.613.61,\,2,\,-3.61). The CG recurrences can still be applied as long as no denominator dTAdd^TAd is zero; α\alpha may then become negative. Take x0=0x_0=0, so r0=br_0=b and d0=r0={1,−12,2}Td_0=r_0=\{1,-12,2\}^T.

Iteration 1

Ad0={5, 18, −35}Tα0=149−281=−0.53025x1={−0.5302, 6.3630, −1.0605}Tr1={3.6512, −2.4555, −16.5587}Tβ0=293.52149=1.97015,d1={5.6214, −26.0973, −12.6184}T\begin{aligned} Ad_0&=\{5,\,18,\,-35\}^T\\ \alpha_0&=\frac{149}{-281}=-0.53025\\ x_1&=\{-0.5302,\,6.3630,\,-1.0605\}^T\\ r_1&=\{3.6512,\,-2.4555,\,-16.5587\}^T\\ \beta_0&=\frac{293.52}{149}=1.97015,\quad d_1=\{5.6214,\,-26.0973,\,-12.6184\}^T \end{aligned}

Iteration 2

Ad1={4.2458, −11.7579, −72.6706}Tα1=293.521247.5=0.23527x2={0.7923, 0.2230, −4.0293}Tr2={2.6523, 0.3108, 0.5388}Tβ1=0.025282,d2={2.7944, −0.3490, 0.2197}T\begin{aligned} Ad_1&=\{4.2458,\,-11.7579,\,-72.6706\}^T\\ \alpha_1&=\frac{293.52}{1247.5}=0.23527\\ x_2&=\{0.7923,\,0.2230,\,-4.0293\}^T\\ r_2&=\{2.6523,\,0.3108,\,0.5388\}^T\\ \beta_1&=0.025282,\quad d_2=\{2.7944,\,-0.3490,\,0.2197\}^T \end{aligned}

Iteration 3

Ad2={8.6031, 1.0082, 1.7475}Tα2=0.30830x3={1.6538, 0.1154, −3.9615}Tr3≈{0, 0, 0}\begin{aligned} Ad_2&=\{8.6031,\,1.0082,\,1.7475\}^T\\ \alpha_2&=0.30830\\ x_3&=\{1.6538,\,0.1154,\,-3.9615\}^T\\ r_3&\approx\{0,\,0,\,0\} \end{aligned}

The residual is zero after three iterations, so iterations 4 and 5 are not needed.

Answer: x1=1.6538 (43/26), x2=0.1154 (3/26), x3=−3.9615 (−103/26)x_1=1.6538\ (43/26),\ x_2=0.1154\ (3/26),\ x_3=-3.9615\ (-103/26). Check: 3(1.6538)−3.9615=1.03(1.6538)-3.9615=1.0, −0.1154−11.8846=−12-0.1154-11.8846=-12, 1.6538+0.3462=21.6538+0.3462=2.

  • 2070 Magh · 12 marks

Write an algorithm and a program (C or Fortran or Matlab) for the fast Fourier transform. With a suitable example explain what parameters can be identified with the help of time domain and frequency domain.

Answer

Fast Fourier transform: idea

The DFT of NN samples is Xk=∑n=0N−1xnWNknX_k=\sum_{n=0}^{N-1}x_n W_N^{kn} with WN=e−i2π/NW_N=e^{-i2\pi/N}, needing N2N^2 operations. The Cooley-Tukey radix-2 FFT (for N=2mN=2^m) splits the series into even and odd samples:

Xk=Ek+WNkOk,Xk+N/2=Ek−WNkOk,k=0,…,N2−1X_k=E_k+W_N^kO_k,\qquad X_{k+N/2}=E_k-W_N^kO_k,\quad k=0,\dots,\tfrac N2-1

and repeats the split log⁡2N\log_2N times. The cost is N2log⁡2N\tfrac N2\log_2N complex multiplications.

Algorithm

  1. Read NN (a power of 2) and the samples xnx_n at interval Δt\Delta t.
  2. Reorder the samples in bit-reversed order.
  3. For stage length len=2,4,8,…,Nlen=2,4,8,\dots,N: compute W=e−i2π/lenW=e^{-i2\pi/len}; for each block, for each k=0…len/2−1k=0\dots len/2-1 form u=xi+ku=x_{i+k}, v=xi+k+len/2 Wkv=x_{i+k+len/2}\,W^k, then set xi+k=u+vx_{i+k}=u+v, xi+k+len/2=u−vx_{i+k+len/2}=u-v.
  4. After the last stage xx holds XkX_k. Amplitude =2∣Xk∣/N=2|X_k|/N, frequency fk=k/(NΔt)f_k=k/(N\Delta t).
 x0 --o----o----o-- X0
 x4 --o----|    |
 x2 --o----o    |   (butterflies:
 x6 --o----|    |    a+Wb , a-Wb)
 ...

Program (C)

#include <stdio.h>
#include <math.h>
#include <complex.h>
#define PI 3.14159265358979323846

/* in-place radix-2 FFT, n must be a power of 2 */
void fft(double complex x[], int n)
{
    for (int i = 1, j = 0; i < n; i++) {      /* bit reversal */
        int bit = n >> 1;
        for (; j & bit; bit >>= 1) j ^= bit;
        j ^= bit;
        if (i < j) { double complex t = x[i]; x[i] = x[j]; x[j] = t; }
    }
    for (int len = 2; len <= n; len <<= 1) {  /* butterfly stages */
        double complex wlen = cexp(-2.0 * I * PI / len);
        for (int i = 0; i < n; i += len) {
            double complex w = 1.0;
            for (int k = 0; k < len / 2; k++) {
                double complex u = x[i + k];
                double complex v = x[i + k + len / 2] * w;
                x[i + k]           = u + v;
                x[i + k + len / 2] = u - v;
                w *= wlen;
            }
        }
    }
}

int main(void)
{
    int n = 8; double fs = 8.0; double complex x[8];
    for (int i = 0; i < n; i++) {             /* 1 Hz (amp 2) + 3 Hz (amp 1) */
        double t = i / fs;
        x[i] = 2*sin(2*PI*1*t) + 1*sin(2*PI*3*t);
    }
    fft(x, n);
    for (int k = 0; k < n; k++)
        printf("f=%.1f Hz  amp=%.3f\n", k*fs/n, 2*cabs(x[k])/n);
    return 0;
}

Example: time domain and frequency domain

Signal x(t)=2sin⁡(2πt)+sin⁡(6πt)x(t)=2\sin(2\pi t)+\sin(6\pi t) sampled at 8 Hz for 1 s (N=8N=8). The program output is:

ff (Hz)01234
amplitude02.00001.0000

(components at k=5,6,7k=5,6,7 are the mirror image of k=3,2,1k=3,2,1.)

  • Time domain shows the amplitude of vibration against time, peak value, duration, arrival time and decay of the signal, but the individual components are mixed together.
  • Frequency domain shows the dominant frequencies (1 Hz and 3 Hz), their amplitudes (2 and 1) and phase. For a structure, the peak frequency is the natural frequency, so resonance with earthquake or machine frequency can be checked; noise is separated by filtering.
  • Frequency resolution is Δf=1/(NΔt)=1\Delta f=1/(N\Delta t)=1 Hz; the highest frequency identified is the Nyquist frequency fs/2=4f_s/2=4 Hz.

Questions from Old Question Collection (CE 751) (IOE BCE CE 751 exam papers from 2070 to 2079). Answers are written for this site; check them against your class notes.

Chapter titles and hours from the IOE syllabus ↗