0% found this document useful (0 votes)
48 views2 pages

MTH308 and MTH308B Lab Assignment 3

This document provides instructions for two programming assignments for a numerical analysis course: 1. Write a C program to perform Gaussian elimination on a system of n linear equations with n unknowns to solve for the unknown variables. The program takes an augmented matrix as input and outputs the solution vector or indicates if no unique solution exists. 2. Write a C program to perform LU decomposition to factor a square matrix A into lower and upper triangular matrices L and U. The program takes the matrix A as input and outputs the factors L and U, or indicates if factorization is not possible. Both assignments require implementing common algorithms for numerical linear algebra - Gaussian elimination for solving systems of equations and LU decomposition for matrix factorization. The

Uploaded by

ritvik goyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views2 pages

MTH308 and MTH308B Lab Assignment 3

This document provides instructions for two programming assignments for a numerical analysis course: 1. Write a C program to perform Gaussian elimination on a system of n linear equations with n unknowns to solve for the unknown variables. The program takes an augmented matrix as input and outputs the solution vector or indicates if no unique solution exists. 2. Write a C program to perform LU decomposition to factor a square matrix A into lower and upper triangular matrices L and U. The program takes the matrix A as input and outputs the factors L and U, or indicates if factorization is not possible. Both assignments require implementing common algorithms for numerical linear algebra - Gaussian elimination for solving systems of equations and LU decomposition for matrix factorization. The

Uploaded by

ritvik goyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab Assignment-3

MTH 308 and & MTH 308B: Numerical Analysis and Scientific
Computing-I
January-April 2024, IIT Kanpur

1. Write a C program on Gaussina Elimination (on n×n system) with backward substitution.
Hint: (You can use the following algorithm)
INPUT : Number of unknowns and equations n, the augmented matrix A = [aij ] for
1 ≤ i ≤ n and 1 ≤ j ≤ n + 1.
OUTPUT: The solution vector x = [xj ] or message that the system has no unique solution.
Step-1: For i = 1, 2, . . . , n − 1 do Steps 2 to 4.

Step-2: Let p be the smallest integer with i ≤ p ≤ n and api ̸= 0.


If no integer p can be found, then OUTPUT (’no unique solution exists’);
STOP
Step-3: If p ̸= i then perform Ri ↔ Rp
Step-4: For k = i + 1, . . . , n do Steps 5 and 6.
Step-5: Set mki = aaki
ii
Step-6: Perform (Rk − mki Ri ) → Rk

Step-7: If ann = 0, then OUTPUT (’no unique solution exists’);


STOP.
Step-8: Set xn = an,n+1
ann
Step-9: For i = n − 1, . . . , 1, set xi = (ai,n+1 − nj=i+1 aij xj )/aii .
P
Step-10: OUTPUT x = [x1 , x2 , . . . , xn ]
STOP.

2. Write a C program on LU decomposition of a square matrix A.


Hint: (You can use the following algorithm)
INPUT: The dimension n and the entries aij , 1 ≤ i, j ≤ n, of A, the diagonal

l11 = l22 = · · · = lnn = 1

of L or the diagonal u11 = u22 = · · · = unn = 1 of U.


OUTPUT: The entries lij , 1 ≤ j ≤ i, 1 ≤ i ≤ n of L and the entries, uij , i ≤ j ≤ n, 1 ≤
i ≤ n of U .
Step-1: Select l11 and u11 satisfying l11 u11 = a11 .
If l11 u11 = 0, then OUTPUT (’Factorization impossible’);
STOP.
Step-2: For j = 2, . . . , n set u1j = a1j /l11 ; or lj1 = aj1 /u11 ;
Step-3: For i = 2, . . . , n − 1 do Steps 4 and 5.
Pi−1
Step-4: Select lii and uii satisfying lii uii = aii − k=1 lik uki .
If l11 u11 = 0 then OUTPUT (’Factorization impossible’);
STOP.

1
h i
1
aij − i−1
P
Step-5: For j = i + 1, . . . , n, set uij = lii k=1 ik kj ,
l u
h Pi−1 i
1
lji = uii aji − k=1 ljk uki .
Pn−1
Step-6: Select lnn and unn satisfying lnn unn = ann − k=1 lnk ukn .
Step-7:
OUTPUT (lij for j = 1, . . . , i and i = 1, . . . , n); and
OUTPUT (uij for j = i, . . . , n and i = 1, . . . , n);
STOP.

End.

You might also like