# MATLAB determining elementary matrices for LU decomposition

I am confused by this question I am studying for MATLAB practice. • What exactly is confusing you? – copper.hat Mar 1 '14 at 23:12
• Can matlab find the individual elementary matricies to solve or do I have to do it by hand? – KnowledgeGeek Mar 1 '14 at 23:23
• I did it by hand, but it didn't seem like a very quick way of doing it – KnowledgeGeek Mar 1 '14 at 23:41
• I presume you are meant to do it by hand for learning purposes? – copper.hat Mar 1 '14 at 23:56
• This is a matlab assignment, I am assuming we use matlab. We haven't done this stuff by hand for months. – KnowledgeGeek Mar 2 '14 at 0:02

I thought this an interesting excercise so, I fired up Octave (poor man's Matlab) and gave it a try. Like I said in my comment, I tried to use Matlab to calculate the elementary matrices using the fact that $E = E_3E_2E_1 = L^{-1}$ but was uncessful. So then I thought that I'd just do row operations and construct the $E_i$ directly. Here is a transcript...

octave:1> A= [1, -2, 3; 2, -6, 5; -1, -4, 0]

A =

$\begin{matrix} 1 & -2 & 3 \\ 2 & -6 & 5 \\ -1 & -4 & 0 \\ \end{matrix}$

octave:2> E1 = [1, 0, 0; -2, 1, 0; 1, 0, 1]

E1 =

$\begin{matrix} 1 & 0 & 0 \\ -2 & 1 & 0\\ 1 & 0 & 1\\ \end{matrix}$

octave:3> E1*A

ans =

$\begin{matrix} 1 & -2 & 3\\ 0 & -2 & -1\\ 0 & -6 & 3\\ \end{matrix}$

octave:4> E2 = [1, 0, 0; 0, 1, 0; 0, -3, 1]

E2 =

$\begin{matrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & -3 & 1 \\ \end{matrix}$

octave:5> E2* (E1*A)

ans =

$\begin{matrix} 1 & -2 & 3 \\ 0 & -2 & -1 \\ 0 & 0 & 6 \end{matrix}$

octave:6>