Lower/Upper Triangular Matracies and LU Factorization

In summary, the conversation discusses how to write a MATLAB function to solve the equation x=B^−1*(2A^−1 + 1)b using LU factorization, forward substitution, and backward substitution. The conversation also highlights the importance of understanding the math behind the code and suggests using test problems to check the function's accuracy. Additionally, a suggestion is made to use a decomposition method to find the inverse of a matrix.
  • #1
playboy

Homework Statement



Let A and B be invertible n×n matrices and b be an n×1 vector.

Write a MATLAB function with inputs (A,B, b) to solve the equation x=B^−1*(2A^−1 + 1)b

Make use of functions "LU Facotrization, Forward Substituion and Backwards Substitution" and DO NOT calculat any matrix inverse.





Homework Equations




PLEASE IGNORE THIS PART FOR NOW AND SKIP TO

The Attempt at a Solution






Well, I came up with the functions for LU Facotrization, Forward Substituion and Backwards Substitution;

LU Facotrization:

function [L,U]=lufactor(A)

n=length(A)
U1=A
L1=eye(n);
..for p=1:n
...for q=p+1:n
...L(q,p)=U(q,p)/U(p,p)
...U(q,p:n)=U(q,p:n)-U(p,p:n)*L(q,p)l
...end
..end



Forward Substition:

function x=forsub(L,b)

[n,n]=size(L);
x=zeros(n,1);
..for i=1:n
... x(i)=(b(i)-L(i,1:i-1)*x(1:i-1)/L(i,i)
..end


Backwards Substition:

function x=baksub(U,b)

[n,n]=size(L);
x=zeros(n,1);
..for i=n:-1:1
... x(i)=(b(i)-L(i,i+1:n)*x(i+1:n)/U(i,i)
..end



The Attempt at a Solution



I wrote the above functions, so that is a start,

But apart from trying to write the code, I am kind of lost in understanding the math - which is much more important.

I want to LU-factorize A and B to get and upper and lower matrix for each of A and B.

With these matracies, how would I go abouts get it's inverse?

Forword substitution solves for x in Lx = b
and
Backword substitutions solves for x in Ux=b

I do not know where to go from here

Could somebody help me out please?
 
Physics news on Phys.org
  • #2
To solve Ax = b, first find L and U. Then

Ax = b
(LU)x = b

Since matrix multiplication is associative you can change the position of the brackets:

L(Ux) = b

Ux is a vector - call it y

First you solve

Ly = b (forward substitution)

Then solve

Ux = y (backward substitution).

BTW I didn't check your code in detail, but you are doing the right sort of things.

To make up an "easy" test problem, you can work backwards: write down some "simple" matrices L and U (say 3x3), then multiply them to get A, then write down a "simple" answer x, then multiply Ax to get b.

Then, test if your functions can work back from A and b to find the L U and x that you first thought of.
 
  • #3
Hi,

A really neat way - and outside of MatLab a really fast way - of solving the inverse of a matrix is to recognise that any matrix, times it's inverse, = the identity matrix.

Which means that when you have a decomposition of any variety - L - then you find the inverse of L to begin with using only forward substitution as follows:

L.Li = I

Where I is the identity matrix and Li is the inverse of L

This is solved by solving 1 column of the inverse at a time:

L.Li = [1,0,0,0...]

and storing that column, then looping back and solving with [0,1,0,0,0...0], then [0,0,1,0,0,0...0] & etc.

The full inverse can then be computed as Li.Li' - i.e. the inverse of the triangular decomposition (or factor) multiplied by it's own transpose.

If you use CSR to store the data, it's really fast too - except for the Triangular x transpose at the end, which can't be avoided.

Cheers,

Mike Li.
New Zealand.
 

FAQ: Lower/Upper Triangular Matracies and LU Factorization

What is a lower/upper triangular matrix?

A lower triangular matrix is a square matrix where all elements above the main diagonal are zero. An upper triangular matrix is a square matrix where all elements below the main diagonal are zero. In both cases, the main diagonal elements can be zero or non-zero.

How is a matrix factorized using LU decomposition?

LU decomposition is a method used to factorize a square matrix into two triangular matrices, one lower and one upper. This is done by finding the lower and upper triangular matrices that, when multiplied together, give the original matrix. This is useful for solving systems of linear equations and finding the inverse of a matrix.

What are the advantages of using LU factorization?

LU factorization is useful for solving systems of linear equations because it reduces the amount of computation needed. Once a matrix is factored into lower and upper triangular matrices, it is easy to solve for different values of the variables in the system. This method is also used in numerical analysis for solving differential equations and optimization problems.

Can LU factorization be applied to non-square matrices?

No, LU factorization can only be applied to square matrices. If a non-square matrix needs to be factorized, other methods such as QR decomposition or singular value decomposition (SVD) can be used.

How is LU factorization related to Gaussian elimination?

Gaussian elimination is a method used to solve systems of linear equations by reducing a matrix to row-echelon form. LU factorization is based on the same idea, but instead of eliminating variables, it finds the lower and upper triangular matrices that, when multiplied together, give the original matrix. In fact, Gaussian elimination can be seen as a special case of LU factorization with some additional simplifications.

Similar threads

Replies
1
Views
1K
Replies
16
Views
4K
Replies
4
Views
2K
Replies
5
Views
2K
Replies
1
Views
9K
Replies
1
Views
5K
Back
Top