Let me now open our ipythonshell and let me
try coding whatever I observed just now . So,
before which I will try tohelp you understand
a few commands, there is something called
the numpy um library which is a storehouse
of a lot of matrix operations functions which
help you meddle with matrices.
So, how do you declare a matrix?
You simply say A equals numpy dot mat and
then you write down your matrix in the form
of the first row followed by a semicolon and
then the second row.
If you remember it right from a previous lecture
we are taking this matrix 1 2 3 4 and then
there is a new vector v that I defined which
is if you remember 1 comma 1, that is defined
in python as 1 space 1,no no that is not right
1 semicolon and then 1 isn't that right.
So, what what does it denote, I am sorry what
does it denote?1 is the first row, 1 is thesecond
row right.
So, when I say A times v now A is a matrix
1 2 3 4 and v is the matrix 1 comma 1.
I get 3 comma 7 which is1 plus 2 and then
3 plus 4 correct that is thethat is the way
in which youmultiply a matrix with the vector.
So, let me now open a new shell ipython shell
and then type a piece of code, to observe
what happens when you keep repeatedly applying
a on the vector v of course, you keep normalizing
it every now and then ok.
So, let me editah mat dot py and what I do
is I say import numpy and then um I will declare
my matrix which is A equals numpy dot mat
1 um single quotes 1 space 2.
And, then semicolon 3 space 4 the close ok
and then my initial vector is going to be
numpy mat 1 semicolon 1.
And now what I am doing is, for i in range10
you know what I am doing here; I say z equals
A of v right and then I need to normalize
this vector right.
Do you remember 1 2 3 4 supplication on 1
comma 1 gave us some value and we pulled that
to the unit circle.
That pulling to the unit circle is done by
the following operation, what you do is z
equals z divided by numpy lin al alg this
is a linear algebra package that is available
within numpy you say norm of z.
So, this one is going to be a real number
whichis basically that what you get.
So, 1 plus 2 is 3 3 plus 4 is 7 this becomes
3 comma 7 when you apply this matrix on 1
comma 1.
And, 3 comma 7 you normalize it what do you
do 3 divided by 3 comma 7 divided by square
root of 3 square plus 7 squared right.
Remember in the previous lecture I am just
doing the same thing here.
After doing this what I do is, I print my
z ok and I print somestars here.
So, that it looks neat it separates two things
um and then I go back here and I simply display
my v for clarity sake; just to tell you from
where we started from correct.
And, this is just beautification do not worry
much this is just for us to read the output
clearly nothing else ok.
So, I am going to say this if you want let
us go through the code once import numpy um
that imports all the library functions, that
numpy has and I declare a matrix 1 2 3 4.
And, thenthe next line is I declare this columnmatrix
1 comma 1 I simply um display what is this
matrix 1 comma 1 here.
And, then I repeat this loop 10 times what
do I do, I apply my matrix A on v and call
it z and then I normalize z.
What do you mean by normalizing z?
You pull it to the unit circle right, that
is what this does linear algebra norm precisely
does that square root of sum of squares nothing
right.
So, now let us say you print z.
Let us see what is the output of this, forget
thewarning message that you keep getting like
this that generally happens because of theits
relation problems.
And, you would not output the write editor
and stuff like that anyway let us ignore it.
So, what I do is run mat dot py and I get
some answer here yes.
So, I start with 1 comma 1, its application
whose application the matrix 1 2 3 4s application
on 1 comma 1 gives me 3 comma 7.
When I normalize 3 comma 7, if you remember
from my previous lecture I indeed got 0.39
and 0.91 there.
The question there was if I repeatedly apply
what do I get?
I am getting the same values as you can see.
It is simply 0.3939193 and 0.91914503 I hope
there is no error with the code, let me just
check the code.
So, yeah there is a problem here indeed this
is the reason why um I think it is good for
us to code together and if there is an error
I will not redo the coding I will correct
it here; so, that you will realize what kind
of mistakes one can do.
So, I have made a very silly mistake here,
I am simply taking z and then applying umassigning
A of v we do it right.
What I should do is, if I want repeated application
after displaying z I should say v equals z.
So, that when I come here I am sorry when
I come here the the next z will be A applied
to my previous z which was v right.
So,the output that I got previously was incorrect
let us redo this.
So, let me say run mat dot py and I get some
values here, let me see what this is 0.39
0.91 as expected and then the next one is
something else.
You see 4175 something the next one is 4158
something, 4159 something, 415973, but this
was 415980 so on and so forth you will observe
that oh my goodness it is converging.
0.41597356 here the next iteration the 10th
iteration was 41597356 precisely the same
as the previous iteration, you will you can
even observe it with this.
So, these two column vectors sort of are the
same,maybe this wasah this converged.
What if, let me do something what if um what
was that mat dot py and so, edit mat dot py
and I will go here and I will try to vary
this 1 comma 1 to let us say 1 comma um let
us say let us say some 3 comma sometime 11
alright.
Now, let us see what happens to this, I come
out the code remains the same I come out and
I execute this; you see what happenslooks
like I am getting the same values how is that.
So, 3 comma 11 gave me this value after normalizing
and application of the matrix A on this gives
me this.
An application of my matrix A on this gives
me this right you see that finally, I am getting
41597356 and 90937671 this looks familiar.
Why?
Let me scroll up and see do you see that this
is precisely the value that we got before,
41599093 come down 41599093 it is exactly
the same.
What do we conclude here?
No, matter where you start from what vector
you start from, when you start applying the
same matrix 1 2 3 4 on any vector, you get
a constant vector.
It converges to a constant vector.
