# Elementary Row Operations (Remarkable Ideas)

(D4M) — Here is the video transcript for this video.

00:00
[Music] hi everyone welcome back um this uh episode we’re going to learn
what elementary row operations are and why they are important
now before we get started though i want to mention that this episode is part of
the series um systems of linear equations in-depth tutorials for linear algebra
and so let’s see what we’re going to do in this episode
so first we’re going to talk about what are row operations
and then we’re going to talk about why do they matter and
and we’re going to look at an example and then we’re going to look at that
same example again and we’re going to do it using python
so this will be an exciting uh video i’m really pumped for it
so let’s get started so here we go um first up we’re going to look at what

00:01
are row operations so in our example so far in the previous
episodes we’ve talked about systems of linear equations and we’ve seen some
that have had no solutions some have had unique solution and some that have
had infinite number of solutions so there’s typically
so we saw typical examples last time of those three different scenarios
so these examples suggest the following definition
which is two linear systems are called equivalent if they have the same
solution set so this is a very important definition right here
and it’s the whole reason behind why row operations are so successful
so i’m going to make a video uh upcoming soon in an upcoming episode we’re going
to see the importance of this definition here and we’re going to see it in the
form of this theorem here so this theorem says linear systems of equations
are equivalent if each can be obtained from the other

00:02
by one or more of the following operations and these operations are
going to be called row operations and so i’m going to prove this theorem
in it in a different episode but for today we’re just going to get the
intuitive idea behind its meaning and so let’s see here let’s move out of
the way and let’s look at these row operations
right here so the first row operation is we can interchange the order of
equations and the second one is we can multiply or
divide one equation by a non-zero scalar and then the third
of the three is add one multiple of one equation to another so now these uh row
operations here are stated in terms of equations
uh but typically the way we use them is in terms of matrices so i’ll talk about
that here in a second but first i want to talk about in terms of equations
because i think it’s here where it’s most intuitive so you know just because you

00:03
write down an equation in which way you write it down doesn’t change its
geometric um you know doesn’t change it as an object as a geometric object
and also the way in which you write down the equation
so for example if i have a line y equals x and i multiply this by two
well we still have the same line this is still a line going right through
the origin right there and if we multiply both sides by two
it’s still the same line so um in the previous episodes we talked
about how these linear equations represent lines and planes and
all right so anyways these are the uh row operations right here and
the idea behind them is that um doing these operations here
doesn’t change the geometric objects they just change their representation of
these objects and so either uh scaling or writing down

00:04
their order or adding one multiple of one equation to another doesn’t change
these geometric objects so what are these row operations so we’re
going to solve uh systems of linear equations using row operations and and
this is also going to be in an upcoming video called gaussian elimination and
then we’ll have another one called gauss jordan elimination
so in this video we’re just going to focus on these row operations though
so let’s look at what they are um now the idea behind the row operations
though is we’re going to start with a linear system of equations
and our output will be a collection of vectors that solve the system so that’s
the goal and the engine behind it all are the row operations
so here’s what i mean more specifically by the row operations so you might also
remember in the last uh video or the last episode we talked about augmented

00:05
matrices so given a system of linear equations we can write down an augmented
matrix and then we can do some row operations to this augmented matrix so we can
interchange two rows so notice how i stated these right here in terms of rows
of a matrix we can multiply row by a non-zero scalar scalar real number
complex number so i’ll just use the generic word scalar add a multiple of
of a row to another row and so here’s the overall strategy
um to solving a system using matrices and these row operations here so the
and then we’re going to use a matrix representation of the system by writing
down its augmented matrix and then we’re going to talk about uh the row echelon
form of a matrix also and that’s going to be another upcoming episode
but we’ll get some intuitive idea of what it means in this video today

00:06
and then the last step of of our strategy here will be to write down the
system um of of of to write down the solution as a set of vectors
so this step right here is actually easy let’s just say easy
and this step right here is also easy so if you have the row echelon form of
the matrix writing down the solution set is easy and if you have this
linear system of equations it’s easy to write down the matrix
representation of it so this step right here is the
has got the complexity behind solving the um you know linear system of
equations right here and this is where we’re going to use the row operations
and so this is really why row operations are so important is because this is
going to have the complexity right here of applying these row operations
and being successful or not in terms of solving the system

00:07
so let’s look at an example so in this example here we’re just going
to get the strategy behind it so here’s the strategy
and we’re going to look at this system right here
so we’re going to look at this up close and in detail
and we’re going to start off with linear system
and then we’re going to write down the augmented matrix now some people prefer
to have a vertical line through here and their augmented matrix um but
you know that’s not necessarily required but you know if you say it’s an
augmented matrix these last column here come from these numbers over here in any
case um you know we have the row echelon form of
the matrix and so what happens is now we can write down the system so
we got the solution right here as the last column so this will be x equals two

00:08
y equals minus one and z equals three and that right there represents the
unique solution to this system right here so as you can see going from here to
here isn’t the hardest part going from here to here isn’t the
hardest part in fact these two processes right here kind of undo each other in
other words um this right here you can think about it as a augmented
matrix for the system and there is the you know equations right there x equals
two y equals minus one is equals three so these two steps are right here are
very easy so how do we go from here to here
how do we use these row operations so that’s what we’re about to see right now
is you know these three row operations in in action
so let’s see them on this um example right here
so here we have a three by three system and now row operations don’t have to be
for three by three system therefore m by n system but this example here is just

00:09
three by three so the first thing we’re going to do is we’re going to write down
the augmented matrix and so we’re going to take the x’s and the y’s and the z’s
and then the last column right here all right so there’s augmented matrix
there so we talked about the augmented matrix in
the previous episode at length so i recommend checking that out if you
haven’t seen it all right so now we’re going to do some
row operation so i’m doing two row operations right here
so this right here is notation for means we’re applying this transformation
right here this row operation so this right here is really short for r1
sorry um r2 is going to be replaced by r2 what it previous was and then plus a
minus 2 times our row one so this is row two is going to become what row two was

00:10
plus a multiple of row one so in other words i’m going to do minus
two times row one and add it to row two and i’m gonna replace all of that with
whatever was in row two so that’s how we’re gonna get our new
row two it’s what was previous plus multiple of row one
so i’m gonna multiply by minus two and add
and we’re replacing to row two so minus two and add we get zero
so multiply by minus two and add we get the one
multiply by minus two and add and we get the minus three
multiply by minus two and add and we get to minus ten so let’s do uh one more
so this uh right here represents that row three
is going to become what row three was plus minus three times row one
so um we’re going to be getting a new row three
so we’re going to be getting a new row three in other words row one and row two
stay the same from what they are and now to do this operation right here

00:11
i’m going to get a new row three right here so here we go we’re going to take
row three plus negative three times row one
so i’m gonna multiply by negative three and add negative three and add
multiply by negative three and add multiply by negative 3 and add and i get
all these numbers right here and so we’ve done two row operations now
now maybe you want to just do one at a time but i went ahead and did two just
so you can see how to do two um but let’s do one now
so this will be the row operation um i’m going to go for
this zero right here so i’m going to try to put a zero right here using this row
operation right here so this row operation right here is r three
is going to become what r three was plus eight times r two
so in other words i’m gonna multiply row two by eight and add it to row three so

00:12
multiply by so i’m gonna multiply by eight and add and i get zero
i multiply by eight and i add and i get zero
i multiply by eight and i add minus four so i get minus 28
and i multiply this by eight and i add and get minus four more so all
total we get minus eighty four so we’re starting to get
some zeros in here the more zeros the easier the system is
right for example if that was zero and that was a zero and that was a zero and
that was a zero the more zeros you have in your as your coefficients the easier
it is to find your answer so i’m trying to get as many zeros as possible
alright so now next i’m going to try to uh get a one here
so i’m going to scale row three so this stands for row 3 is going to become
minus 1 28 of what row 3 was in other words i’m just multiplying row

00:13
3 by minus 1 over 28 so i multiply by minus 1 over 28 times 0
then times 0 again and then times already a minus 28 so when i multiply
these two together i get what i want which is a 1
and then i also have to do minus 28 over under minus 84 i get a 3 here
all right so very good so there’s our rope there’s a one two three four four
row operations so far we got zeros underneath and one’s down so this
equation right here represents the equation zero x plus zero y
plus one z equals three so this is just z equals three okay
so we have already found the z now what we need to keep in mind is that
theorem that we stated um earlier which said that if you’re going to apply
row operations that whatever system we get at the end will have the same

00:14
solution set as the system right here and that’s critically important because
we don’t want to be doing all these transformations all these row operations
would and then be changing our solution set right that won’t be any good for us
so we’re going to keep the same solution set
but we’re going to be applying these row operations and come up with another
linear system that has the same solutions but the solutions will be very
easy to find and we’re getting close because we already found z z z is equal
to three but we can do some more row operations in fact i’m going to do two more
so this row operation means i’m going to replace row two with
row two plus three times row three so in other words i’m gonna multiply row
three by three and add it to row two so i’m gonna be multiplying by 3 and adding
and that’s going to give me that 0 right here so um
let’s see here now i’m going to be multiplying by 3 here and adding it to

00:15
this one right here so i’m going to multiply by 3 and add multiply by 3 and
add multiply by 3 and add and i’m going to multiply by 3 and add it to minus 10
and there’s where i get the minus 1. so we’ve changed row 2
but i’m also going to change row one here
and so right now i have a one and a one and so i’m going to get a zero right
here now so i’m going to change this one to a zero i’m going to do that right
here by multiplying by minus 1 and adding to row 1. so multiply by minus 1
and add we get 0 multiply by -1 and add we get 2
multiply by -1 and add we get to zero right there and multiply by minus one
and add and we get to zero right here so good after doing these two row
operations right here uh we get this um matrix right here
and then one last time because i want to try to get a zero here if i can i’m
gonna use this one to get a zero here so i’m going to

00:16
multiply by minus two and add so here we go i’m going to keep the same these two
rows the same i’m just going to replace row one
so i’m gonna multiply by minus two and add i still get a one
multiply by minus two and add i get the zero that i want
multiply by minus two and add and we get the two there and so now we have the
uh this is certainly in row echelon form actually after the row echelon form
episode we’re also going to do a reduced row echelon
form episode and it’ll talk about how every uh matrix can be reduced to a
unique matrix in reduced row echelon form in any case
this system this matrix right here represents this system
this matrix right here represents the system
x equals two y equals minus one and z equals three
and that is in fact the solution so we can write the solution as a single

00:17
vector which is just two minus one and then three
and so that would be the solution vector
or if you want to write it out i’m using x y and z there’s your unique solution
right there so that’s great but now let’s see how to do this using uh python
now i chose python because number one it’s free it’s easy to get set up on any
computer whether using a mac windows or android and in fact you can do so
without installing anything if you want to use google collab
um i’ll put some links in the description below
in any case uh let’s see how we can get this set up and working here
so let’s see our setup here so i’m in a um python notebook here and
what i’m going to do is i’m going to import uh some display here to make it

00:18
easier to look at some arrays here because ultimately when we start working
with computer we’re going to need a way to display our arrays
so i’m going to execute this cell right here i’m going to hit shift enter
and what i must what i’m also going to do is i’m going to cook up a
print matrix function which is going to take in an array which i intend to be a
matrix right here it’s going to go through the array and
it’s going to print it out and make it look like math
and so this this this will make it look a lot friendlier to read so i’m going to
execute this cell right here so we’ll use this print matrix function
as we move along here right so now let’s look at some row
operations well the first thing we need to do is uh figure out how to enter some
matrices in so let’s look at how to enter some matrices here
so here i’m going to be entering this matrix called a

00:19
and the matrix is going to be a collection of rows so here’s the first
row here’s the second row here’s the third row
this is going to be a three by three matrix right here i’m going to execute that
and then i’m going to execute the next cell which is just going to tell me what
a is so here it tells me what a is and so as
you can see here this doesn’t look like the same way that it looks like
if we were to write it out mathematical style so
i’m going to execute this next cell right here called print matrix so it’s
going to take this uh right here this matrix right here it’s going to print it
out right here and now it looks like something that you would see in math
so that’s the print matrix so here’s how we’re going to input a matrix just by
typing this up here and then we’re going to output it using
the print matrix form right here all right so now let’s look at the first
row operation number one which is called switching rows
so this is how we’re going to switch our rows

00:20
we’re going to take in a matrix capital m and we’re going to input at i and a j
and so that’s going to tell us which rows to switch
and so here’s how we would do that we would set m1
the uh i throw here to be the j throw and the jth row to be equal to the i throw
and then we’re going to print out that matrix and give it back to us
so let’s execute that and then we’re going to um take this
matrix here a which we inputted a minute
ago and we’re going to run that function
on it switch rows so i’m going to switch rows
zero row with the first row oh wait a minute what is zero row means all right
so when we’re working over here in math we talk about row one row two row three
right so this would be row one row two row three
but when we’re talking with a computer uh usually computer programming

00:21
languages start at zero so this zero row first row second row
so i’m going to switch the zero row with the first row so i’m going to switch
these two rows right here and there’s the output right there so
you can tell these right here have been switched on them
and so to switch to rows all we got to do is run this little function right here
all right good so now what about uh scaling rows so to scale some rows
we’re going to um hook up another little function here
called scaling functions so definition scaling rows
so we’re going to take in a matrix we’re going to take in a constant that
should be non-zero and we’re going to tell it what row to apply that scalar to
so this will be uh scaling a row multiplying an equation by a non-zero constant
all right so first thing is i need to figure out how long that row is so

00:22
that’s what the little m is is how long that row is and then for everything in
that row so i’m going to go one by one through that row
and i’m going to take that entry and multiply it by the constant and and set
that entry back in there and then i’m going to print out the matrix here
all right so let’s execute this function right here and then
we’ll go and try to use it and so what we found here is that this
matrix here a same matrix we keep working with
um but i’ve switched row a scaled row of scaled row um 1 by
um which is not a row operation by the way so let’s change that to a two
you can see that it worked though so let’s change that to a two
and then execute that again now you can see that we scaled row two
uh by a factor of two or if you want to think about it in

00:23
terms of programming we scaled row one this is row zero this is row one so we
scaled row one by a factor of two so we can do it by factor of point two
if we want there we go we scaled it by a factor of point two
all right so they’re scaling rows and then now we’re going to do
the how to add a row to a scalar multiple of another row
all right so let’s do that now so here we go let’s see if we can scoot
this over a little bit so adding a row to scare the multiple of another row
all right so i abbreviated all that by asmr adding scalar multiple to a row all
right so we’re going to take in a matrix and we’re going to take in a row
and we’re going to take in a scalar and another row

00:24
so first thing i’m going to do is mult find out how long the row is how how
long a row is then we’re going to iterate through a whole row
and we’re going to assign a new value to
that row it’s going to be what the value was plus c times the
value of the other row so we’re going to do the same operation there that we’re
doing um you know in our example that we did when we did our row operations here
so let’s go ahead and execute that and then now let’s see an example right here
so this right here um is taking so we have our matrix a same matrix that
we’ve been working with and here you can see
that we’ve done row zero we’ve changed row zero we took what it was
plus two times row one so it was a one right here you can see it’s a one
and then it was this four so two times row one so two times the four plus one

00:25
and then um we have the 12 here because we’re going to do um you know
let’s see here it’s right here so we’re going to do
2 times 5 plus 2 that gives us the 12. and then 2 times the 6 plus the 3
that gives us the 15. so we’re changing row 0
and that’s how the change works right there and we’re going to keep the same
the red the rest of it the same right there all right so there’s the um three
definitions that we need to do the three row operations right there
all right so now let’s look at an example and so this is the same example we did
by hand same x’s same y same z same all right so first off is we need to
input the matrix so we’re going to call this matrix a
so i’m looking at one two one three there’s the first row

00:26
and two five minus one minus four so we’re setting up our augmented matrix
right here and we have three minus two minus one five for our last
row right there so there very good there’s our augmented matrix so let’s go
ahead and execute that cell right there all right so now
we’re going to do a row operation here now i want a 1 right here and i already
have a 1 so i’m not going to bother to scale this row right here
now the strategy that i’m talking about here we’re going to go through in great
detail after we talk about what row echelon is
and what reduced row echelon is so as we continue going throughout this series
here the a method called gas elimination will become
crystal clear and you’ll be very good at it by the time the series is over
in any case um i want a one here and so i already
have it now i’m going to use this one to get zeros here

00:27
by using this uh function here asmr right adding a scalar multiple to
another row so i’m going to change row one which is the second row
here i’m gonna multiply by minus two and i’m gonna add so
multiply by minus two and add i get this right here my multiplied by minus two
and add that’s where i get the one multiply by minus two and add that’s
where i get to minus three and multiply by minus two and add and there’s where i
get the minus ten and so i can accomplish that by just
executing this cell right here all right now i want to get a
0 here so i’m going to multiply by minus 3 and add so i’m going to do this right
here so what does this right here mean so i’m going to multiply i’m going to
change out row 2 which is row three here and
so i’m gonna multiply by minus three times row zero so minus three here and

00:28
add it to here so i get a zero and minus three and then i add i get minus eight
and then minus three and add i get minus four
and then minus three and i add and i get minus four here
so let’s execute that cell and then we get our matrix here and so
what we’ve accomplished so far is our first column is exactly as we want it we
have a one and nothing but zeros above and below it
now the goal is to get a one here we have it
so now i’m going to use this one to get zeros above and below it if possible
so i’m going to multiply this by two and add it
and that’s what this function right here does so i’m going to execute that
as you can see we get our zero here now i want to get a zero here so now i’m
gonna multiply this by eight and i’m gonna add it here of course we have to
do it by the whole row multiply by eight
and add multiply by eight and add and we can do that by executing the cell right

00:29
here and so now we have the zeros up and up and down so now i want a one here
well i don’t have a one here so i’m going to scale
so i’m going to multiply this whole row by one over this and
so i’m going to get a one when i’m done with that so good now we have scaled
i find it interesting that it changes these two minuses in any case um
we multiply this by minus 1 over 28 by the whole row here by
by row 2 here all the way then it’s going to get a one here for us
notice as we keep proceeding through here the numbers over here keep changing
right so we’re building our solution slowly slowly
okay so now we have a one here just as we’d like
and so i’m gonna use this one to get zeros above and below
so i’m gonna multiply by minus seven or i’m gonna use uh i’m

00:30
gonna get this one right here first so i’m gonna multiply by three and i’m
gonna add and that’s what this uh operation right here does all right
and so we got our zero here as we want and now
we’re going to get a zero here so i’m gonna multiply row two by minus seven
and add it to row zero or row one all right so let’s execute that
and then you can see that we got our solution
this uh row right here comes out to be x equals two y equals minus one and z
equals three and there we have it um you know there’s what the row operations
are and why they are important um i want to say thank you for watching
and i’ll see you in the next episode if you like this video please press this
button and subscribe to my channel now i want to turn it over to you math can be

00:31
difficult because it requires time and energy to become skills i want you to
tell everyone what you do to succeed in your studies either way let us know what