How to Implement Gaussian Elimination in MATLAB?

Click For Summary
The discussion focuses on implementing Gaussian elimination in MATLAB, emphasizing the importance of partial pivoting for accuracy. Participants are tasked with solving a series of equations using both manual and computational methods, with specific attention to the decomposition PA = LR and back substitution techniques. The second question involves finding the inverse of a matrix using its columns as vectors, while the third question requires solving a large matrix equation and assessing the results through the L2 norm. Users are encouraged to reference existing MATLAB examples and resources for guidance. The thread highlights the necessity of understanding both the theoretical and practical aspects of Gaussian elimination in computational settings.
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