How to Implement Gaussian Elimination in MATLAB?

Click For Summary
SUMMARY

This discussion focuses on implementing Gaussian elimination in MATLAB, specifically emphasizing the importance of partial pivoting for accuracy. Users are guided through solving a system of equations using the decomposition PA = LR, followed by back substitution to find the solution vector x. The discussion also addresses calculating the inverse of a matrix using its LR decomposition and assessing the quality of results through the L2 norm. Resources such as MATLAB examples and external links are provided for further assistance.

PREREQUISITES
  • Familiarity with Gaussian elimination and partial pivoting techniques
  • Understanding of matrix decomposition, specifically PA = LR
  • Basic knowledge of MATLAB programming and syntax
  • Concept of L2 norm for assessing solution accuracy
NEXT STEPS
  • Research "MATLAB matrix decomposition functions" for practical implementation
  • Explore "MATLAB back substitution algorithms" to enhance solution techniques
  • Learn about "L2 norm calculation in MATLAB" for error assessment
  • Investigate "partial pivoting in MATLAB" for improved numerical stability
USEFUL FOR

Students and professionals in mathematics, engineering, and computer science who are working on numerical methods, specifically those implementing Gaussian elimination and matrix operations in MATLAB.

aznkid310
Messages
106
Reaction score
1

Homework Statement



The point of this homework is to experiment with Gaussian elimination, and to
develop an appreciation for partial pivoting. Questions 1 & 2 can be done with a
calculator (though a computer is preferred). Question 3 requires a computer – you
do not necessarily have to write any programs: C++ examples are on the class
web page, and Matlab examples are all over the web. Use whatever you like, but
give credit to your sources.
Q1)

[2.0 1:0 1:0 [ x1 [2.0 + 10e-10
1.0 10e-10 10e-10 x2 = -10e-10
1.0 10e-10 10e-10] x3] 10e-10]

Solve this equation for x using partial pivoting. Strive
to achieve the most accurate results possible (e.g., double precision). First obtain
the decomposition
PA = LR
then use this decomposition to determine x with two back substitution steps:
Ly = (Pb)
Rx = y

Q2) The identity matrix I can be thought of as a collection of vectors:
I = (e1e2...en)
where ei is a vector of length n that is zero, except in the ith component which is 1.

If one were to represent the inverse matrix A^-1 as a collection of vectors,
A^-1 = (a1a2...an).

Then the ith column of A^-1 can be determined by solving Aai = ei. Or, using our
LR decomposition, LR(ai )= P(ei). Use this to find the inverse of the matrix in (1)
with P,L,R from partial pivoting. Assess the quality of the result by computing
(A^-1)A.

Q3) For n = 60, solve
Ax = b
where n n matrix A is given by
Ai j =r2n + 1sin2i j2n + 1
i; j = 1 to n;

and where b is given by the n-long vector of ones. With trivial pivoting, and with
partial pivoting, calculate r = b-Ax. Present sqrt(r*r) (aka the L2 norm krk2), which
should be zero with perfect math.

Homework Equations



I was able to do #1 with a calculator and by hand, and I understand the basic ideas of 2 and 3, but I don't know how to implement them in MATLAB.

The Attempt at a Solution



For #1, i get
x = 4
-2
2
 
Last edited:
Physics news on Phys.org

Similar threads

Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
34K
  • · Replies 1 ·
Replies
1
Views
19K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
27K