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 for a symmetric, positive definite matrix . It is equivalent to minimising the quadratic energy
whose minimum is exactly the solution of . The minimum is searched along directions that are A-conjugate, i.e. for . Each step minimises along one direction without spoiling the earlier ones, so in exact arithmetic the solution is reached in at most steps for an system. The residual is the negative gradient of .
Compared with direct elimination, CG needs only matrix-vector products, so it stores only the non-zero terms of . It is good for large sparse systems, and rounding errors do not accumulate in a long elimination.
Algorithm
- Choose a starting vector (usually ). Compute the residual and set the first search direction .
- For repeat:
- Step length:
- Update the solution:
- Update the residual:
- Check convergence: stop if tolerance.
- Direction factor:
- New direction:
- The last is the solution.
Convergence is faster if 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.
Similar questions: Conjugate gradient numerical (3,0,2 system) (2071 Bhadra)
Answer
Matrix form: , . is symmetric and positive definite. Start with .
, .
Iteration 1
Iteration 2
Iteration 3
The residual is zero after iterations, as expected for CG.
Answer: . (Check: , , .)
- 2071 Bhadra · 5 marks
Solve the given system of equations using the conjugate gradient method.
Similar questions: Conjugate gradient numerical (2,-1 system) (2078 Chaitra)
Answer
is symmetric and positive definite (leading minors ). . Take : , .
Iteration 1
Iteration 2
Iteration 3
Answer: . Check: , , .
- 2079 Jestha · 8 marks
Explain the solution methods of solving a system of linear equations with examples.
Answer
A system 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 to upper triangular form, then back-substitute.
- LU decomposition / Cholesky ( for symmetric positive definite matrices): factor once, then solve for several right-hand sides.
- Gauss-Jordan and matrix inverse.
Example: . Eliminating, gives , so , .
Iterative methods
Start from a guess and improve it until the change is small. They suit large sparse systems.
- Jacobi:
- Gauss-Seidel: same but uses new values immediately.
- SOR: Gauss-Seidel with relaxation factor .
- Conjugate gradient: minimises for symmetric positive definite .
Example (Gauss-Seidel): , start .
- Iteration 1: , .
- Iteration 2: , .
The values move to the exact solution , .
Comparison
| Direct | Iterative |
|---|---|
| Fixed operations, exact | Approximate, needs convergence |
| Fill-in destroys sparsity | Keeps sparsity, low memory |
| Best for small/medium systems | Best 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. for . The half-bandwidth is
A symmetric matrix of order and half-bandwidth is stored with only numbers instead of .
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 . 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 instead of .
- 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 and need diagonal dominance (or symmetry and positive definiteness) for convergence.
- Jacobi method: every unknown is computed using values of the previous iteration only.
- Gauss-Seidel method: newly computed values are used immediately in the same iteration:
It converges about twice as fast as Jacobi. 3. Successive over-relaxation (SOR): with 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 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 .
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 (, , ), so it converges. Rearranging:
Start .
| Iteration | |||
|---|---|---|---|
| 1 | 0.8333 | 3.6333 | 3.6974 |
| 2 | 0.7156 | 3.2384 | 3.9373 |
| 3 | 0.9143 | 3.0548 | 3.9903 |
| 4 | 0.9823 | 3.0094 | 3.9990 |
| 5 | 0.9973 | 3.0011 | 4.0000 |
| 6 | 0.9997 | 3.0000 | 4.0000 |
Example of iteration 1: ; ; .
Answer: (exact solution ).
- 2077 Chaitra · 3 marks
Explain with relevant examples how banded matrix and skyline storage scheme optimize the memory.
Answer
In FEM the stiffness matrix is symmetric, sparse and has non-zero terms only near the diagonal. Storing the full matrix wastes memory.
Banded storage
Only the band is stored: the diagonal and the upper terms of each row (using symmetry). Half-bandwidth dof per node.
Example: a bar of 100 nodes (1 dof), elements connect nodes and , so . Full storage numbers; banded storage 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 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
- Choose a starting vector (usually ). Compute the residual and set the first search direction .
- For repeat:
- Step length:
- Update the solution:
- Update the residual:
- Check convergence: stop if tolerance.
- Direction factor:
- New direction:
- The last 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 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
using the starting vector , carry out two iterations of the conjugate gradient method and show the result.
Answer
Linear system is solved by:
- 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 for symmetric positive definite , and the matrix inverse. In FEM they use banded or skyline storage.
- 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.
| Direct | Iterative |
|---|---|
| Fixed operation count | Number of iterations depends on tolerance |
| Fill-in within band/skyline | Keeps sparsity |
| Good for many load cases (factor once) | Good for very large systems |
Conjugate gradient, two iterations
, , .
, so
Iteration 1
Iteration 2
Answer: after two iterations with residual . A third iteration gives the exact solution (the system has 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 equally spaced samples of a signal in the time domain into complex frequency components :
and the inverse is
gives the amplitude and the phase of the component at frequency . Direct evaluation needs 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 ):
This "butterfly" operation reduces the work to multiplications, so 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:
Answer
(symmetric, positive definite), . Take , so , .
Iteration 1
Iteration 2
Iteration 3
| Iteration | ||||
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 12 |
| 1 | 1.2000 | 0 | 0 | 7.2 |
| 2 | 2.1818 | 1.6364 | 0 | 3.273 |
| 3 | 2.4000 | 2.0000 | 0.8000 | 0 |
Answer: . Check: , , .
- 2073 Magh · 4+4 marks
Write down the algorithm for the conjugate gradient method. Consider the system
Solve the above system by using Gauss-Seidel iteration starting with .
Answer
Algorithm for the conjugate gradient method
- Choose a starting vector (usually ). Compute the residual and set the first search direction .
- For repeat:
- Step length:
- Update the solution:
- Update the residual:
- Check convergence: stop if tolerance.
- Direction factor:
- New direction:
- The last is the solution.
The method needs a symmetric positive definite matrix and gives the exact solution in at most steps.
Gauss-Seidel solution
The matrix is diagonally dominant (, , ), so Gauss-Seidel converges. Rewrite the equations:
Start with and use the newest values at once.
| Iteration | |||
|---|---|---|---|
| 1 | 1.0000 | -0.8333 | -0.1875 |
| 2 | 0.5833 | -0.8264 | 0.0234 |
| 3 | 0.5868 | -0.7567 | 0.0479 |
| 4 | 0.6217 | -0.7543 | 0.0313 |
| 5 | 0.6228 | -0.7600 | 0.0286 |
| 6 | 0.6200 | -0.7605 | 0.0298 |
| 7 | 0.6198 | -0.7600 | 0.0301 |
| 8 | 0.6200 | -0.7600 | 0.0300 |
Example of iteration 1: ; ; .
Answer: .
- 2072 Asoj · 5+3 marks
Explain different solution techniques of linear equations. Write the algorithm for the conjugate gradient method.
Answer
Linear system is solved by:
- 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 for symmetric positive definite , and the matrix inverse. In FEM they use banded or skyline storage.
- 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.
| Direct | Iterative |
|---|---|
| Fixed operation count | Number of iterations depends on tolerance |
| Fill-in within band/skyline | Keeps 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 for a symmetric, positive definite matrix . It is equivalent to minimising the quadratic energy
whose minimum is exactly the solution of . The minimum is searched along directions that are A-conjugate, i.e. for . Each step minimises along one direction without spoiling the earlier ones, so in exact arithmetic the solution is reached in at most steps for an system. The residual is the negative gradient of .
- Choose a starting vector (usually ). Compute the residual and set the first search direction .
- For repeat:
- Step length:
- Update the solution:
- Update the residual:
- Check convergence: stop if tolerance.
- Direction factor:
- New direction:
- The last 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 to triangular form, while the conjugate gradient (CG) method is an iterative method that minimises along A-conjugate directions. CG is preferred for large problems for these reasons:
- Memory: CG needs only matrix-vector products , so only the non-zero terms of the sparse matrix are stored. Gaussian elimination produces fill-in, which destroys sparsity inside the band.
- Operation count: each CG iteration costs about operations, and a good solution often comes in far fewer than iterations, whereas elimination costs about (or for a banded matrix).
- Accuracy: round-off errors in elimination accumulate over steps; in CG each iteration uses the original matrix and corrects the error.
- 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.
- Parallelism: matrix-vector products are easy to parallelise, and the matrix need not even be assembled (element-by-element products).
- In exact arithmetic CG finishes in at most 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).
Answer
, . is symmetric (but not positive definite, as its eigenvalues are ). The CG recurrences can still be applied as long as no denominator is zero; may then become negative. Take , so and .
Iteration 1
Iteration 2
Iteration 3
The residual is zero after three iterations, so iterations 4 and 5 are not needed.
Answer: . Check: , , .
- 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 samples is with , needing operations. The Cooley-Tukey radix-2 FFT (for ) splits the series into even and odd samples:
and repeats the split times. The cost is complex multiplications.
Algorithm
- Read (a power of 2) and the samples at interval .
- Reorder the samples in bit-reversed order.
- For stage length : compute ; for each block, for each form , , then set , .
- After the last stage holds . Amplitude , frequency .
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 sampled at 8 Hz for 1 s (). The program output is:
| (Hz) | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| amplitude | 0 | 2.000 | 0 | 1.000 | 0 |
(components at are the mirror image of .)
- 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 Hz; the highest frequency identified is the Nyquist frequency 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 ↗