Academic Block

Numerical Linear Algebra and MATLAB Get Certified

Numerical Linear Algebra is a core topic in scientific computing, focusing on the application of linear algebra techniques to real-world numerical problems. MATLAB offers a robust environment for performing these operations efficiently.

Solving Systems of Linear Equations

MATLAB provides efficient methods for solving systems of linear equations. Let’s consider the system of equations:

3x - 2y = 5
 x + 4y = 6
            
% Solving a System of Linear Equations
A = [3 -2; 1 4];
b = [5; 6];
x = A \ b;  % Solve Ax = b
disp('Solution x:');
disp(x);

Expected output:

Solution x:
    2.2857
    0.9286

LU Decomposition

LU decomposition factors a square matrix A into a lower triangular matrix L and an upper triangular matrix U, such that A = L * U. Let’s consider:

Matrix A:

4   3
6   3
            
% LU Decomposition
A = [4 3; 6 3];
[L, U] = lu(A);  % Perform LU decomposition
disp('Lower Triangular Matrix L:');
disp(L);
disp('Upper Triangular Matrix U:');
disp(U);

Expected output:

Lower Triangular Matrix L:
    0.6667    1.0000
    1.0000         0
Upper Triangular Matrix U:
     6     3
     0     1

Eigenvalues and Eigenvectors

Eigenvalues and eigenvectors are critical for stability analysis, vibration analysis, and solving systems of differential equations. Consider the matrix:

Matrix A:

2   1
1   2
            
% Finding Eigenvalues and Eigenvectors
A = [2 1; 1 2];
[V, D] = eig(A);  % Compute eigenvalues and eigenvectors
disp('Eigenvectors:');
disp(V);
disp('Eigenvalues (Diagonal Matrix):');
disp(D);

Expected output:

Eigenvectors:
   -0.7071    0.7071
    0.7071    0.7071
Eigenvalues (Diagonal Matrix):
     1     0
     0     3

The sign of an eigenvector is not unique, so the signs you see can differ between MATLAB releases.

QR Decomposition

QR decomposition factors a matrix A into an orthogonal matrix Q and an upper triangular matrix R, such that A = Q * R. Let’s consider the matrix:

Matrix A:

 12  -51   4
  6  167 -68
 -4   24 -41
            
% QR Decomposition
A = [12 -51 4; 6 167 -68; -4 24 -41];
[Q, R] = qr(A);  % Perform QR decomposition
disp('Orthogonal Matrix Q:');
disp(Q);
disp('Upper Triangular Matrix R:');
disp(R);

Expected output:

Orthogonal Matrix Q:
   -0.8571    0.3943    0.3314
   -0.4286   -0.9029   -0.0343
    0.2857   -0.1714    0.9429
Upper Triangular Matrix R:
  -14.0000  -21.0000   14.0000
         0 -175.0000   70.0000
         0         0  -35.0000

Singular Value Decomposition (SVD)

SVD is a robust tool for solving ill-conditioned systems, data compression, and image processing. Let’s consider:

Matrix A:

 1   0
 0   2
 3   0
            
% Singular Value Decomposition
A = [1 0; 0 2; 3 0];
[U, S, V] = svd(A);  % Perform SVD
disp('Matrix U:');
disp(U);
disp('Diagonal Matrix S:');
disp(S);
disp('Matrix V:');
disp(V);

Expected output:

Matrix U:
   -0.3162         0   -0.9487
         0    1.0000         0
   -0.9487         0    0.3162
Diagonal Matrix S:
    3.1623         0
         0    2.0000
         0         0
Matrix V:
    -1     0
     0     1

The signs of the columns of U and V are not unique, so they can differ between MATLAB releases. The singular values are always the same.

Cholesky Decomposition

Cholesky decomposition is used for solving systems of linear equations and for numerical optimization. It decomposes a positive definite matrix A into a product of a lower triangular matrix L and its transpose: A = L * L'.

Consider the matrix:

Matrix A:

 4   12  -16
12   37  -43
-16 -43   98
            
% Cholesky Decomposition
A = [4 12 -16; 12 37 -43; -16 -43 98];
L = chol(A, 'lower');  % Perform Cholesky decomposition
disp('Lower Triangular Matrix L:');
disp(L);
disp('Reconstructed Matrix A from L:');
disp(L * L');

Expected output:

Lower Triangular Matrix L:
     2     0     0
     6     1     0
    -8     5     3
Reconstructed Matrix A from L:
     4    12   -16
    12    37   -43
   -16   -43    98

Determinant Calculation

The determinant of a square matrix is a scalar value used to determine invertibility and other properties. Consider:

Matrix A:

 1   2   3
 0   4   5
 1   0   6
            
% Determinant of a Matrix
A = [1 2 3; 0 4 5; 1 0 6];
detA = det(A);  % Compute determinant
disp('Determinant of A:');
disp(detA);

Expected output:

Determinant of A:
   22.0000

Moore-Penrose Pseudoinverse

The pseudoinverse is used to find solutions to overdetermined or underdetermined systems. Consider the matrix:

Matrix A:

 1   0   2
 0   1   3
            
% Pseudoinverse of a Matrix
A = [1 0 2; 0 1 3];
pinvA = pinv(A);  % Compute pseudoinverse
disp('Pseudoinverse of A:');
disp(pinvA);

Expected output:

Pseudoinverse of A:
    0.7143   -0.4286
   -0.4286    0.3571
    0.1429    0.2143

Norm of a Matrix

The norm of a matrix measures its size or length in a specific sense. Consider:

Matrix A:

 1   -2
 3    4
            
% Norm of a Matrix
A = [1 -2; 3 4];
normF = norm(A, 'fro');  % Frobenius norm
norm1 = norm(A, 1);      % 1-norm
normInf = norm(A, Inf);  % Infinity norm
disp('Frobenius Norm:');
disp(normF);
disp('1-Norm:');
disp(norm1);
disp('Infinity Norm:');
disp(normInf);

Expected output:

Frobenius Norm:
    5.4772
1-Norm:
     6
Infinity Norm:
     7

Matrix Rank

The rank of a matrix is the dimension of its row or column space. For:

Matrix A:

 1   2   3
 4   5   6
 7   8   9
            
% Rank of a Matrix
A = [1 2 3; 4 5 6; 7 8 9];
r = rank(A);  % Compute rank
disp('Rank of A:');
disp(r);

Expected output:

Rank of A:
     2

Least Squares Solution

For overdetermined systems, the least squares method minimizes the error. Consider:

System:
2x + y = 3
 x + 2y = 4
 x +  y = 1
            
% Least Squares Solution
A = [2 1; 1 2; 1 1];
b = [3; 4; 1];
x_ls = A \ b;  % Solve using least squares
disp('Least Squares Solution:');
disp(x_ls);

Expected output:

Least Squares Solution:
    0.5455
    1.5455

Useful MATLAB Functions

Function
Explanation
eig
eig(A) computes the eigenvalues and eigenvectors of A.
svd
svd(A) computes the Singular Value Decomposition of A.
lu
lu(A) performs LU decomposition of A.
qr
qr(A) performs QR decomposition of A.
\
A \ b solves the system of linear equations Ax = b.

Practice Problems

Test Yourself

1. Perform LU decomposition on a 3×3 matrix and verify the result.

2. Find the eigenvalues and eigenvectors of a symmetric matrix.

3. Solve the system of equations using QR decomposition.

4. Compute the SVD of a 3×2 matrix and explain the significance of the singular values.

5. Perform Cholesky decomposition on a symmetric positive definite matrix and verify the result.

6. Compute the determinant of a 4×4 matrix and check if it is invertible.

7. Find the pseudoinverse of a rectangular matrix and verify the property A * pinv(A) * A = A.

8. Compute the rank and norms (Frobenius, 1-norm, infinity norm) of a random 3×3 matrix.

9. Solve an overdetermined system using the least squares method.