| |
 |
|
|
Science Forum Index » Math - Symbolic Forum » a small note about using Mathematica for Linear Algenbra
Page 1 of 1
|
| Author |
Message |
| Nasser Abbasi |
Posted: Mon May 14, 2007 7:47 pm |
|
|
|
Guest
|
I wanted to chat a little about this for sometime, but keep forgetting.
I think using Mathematica for linear algebra can be really confusing for
some one who is used to working with standard linear algebra conventions and
using tools such as Matlab.
To start with, Mathematica does not even have the concept of a row vs column
vector.
Secondly, what one would normally expect to be a column vector comes out to
be a row vector in Mathematica.
This is a simple example.
Given a matrix A, and we want to find its eigenvectors. Lets say it has 2
eigenvectors. Every where one looks, the eigenvectors are presented as
columns in the result. So the result of calling a function which returns
eigenvectors of a matrix is another matrix, whose *columns* are the
eigenvectors. This is the standard and 'common' way.
However, in Mathematica, things come out as lists within lists, and so when
one displays the matrix which contains the eigenvectors, the eigenvectors
are *rows* and not columns, because each list represents one eigenvector,
and each list is a row. This means when one is using Mathematica in this
example, one must remember to transpose the output to make it look as one is
'used' to seeing. Even the Mathematica help example on Eigenvector does a
Transpose on the result to make it look like the standard way.
Here is an example:
A = {{5, 20}, {20, 80}};
v = Eigenvectors[A]
Out[34]= {{1, 4}, {-4, 1}}
Notice that the first list is {1,4}, this is the first eigenvector. The
second list is the second eigenvector. Now when one displays this list of
lists as a matrix using MatrixForm[] to see it more clearly, the first
eigenvector is displayed as the first row, and the second as the second row.
v=[1 , 4 ]
[-4, 1 ]
Now if you show the above v matrix to any one who works in Linear Algebra
allot, and tells them this matrix contains the eigenvectors, I bet you that
99% of them will then say the first eigenvector is the first column and the
second eigenvector is the second column. Then they will be wrong. Because it
should be
v=[1 , -4]
[4 , 1]
This is not an earth shattering thing. In a way it like some languages start
the index at 0 and some at 1, and one can try to get used to it.
But I just wanted to point out, that the above can be confusing to someone
using Mathematica for LinearAlgbera for first time, because these things are
really important, i.e. columns and rows and things like that, for linear
algebra.
Thank you for listening.
Nasser |
|
|
| Back to top |
|
| Valeri Astanoff |
Posted: Tue May 15, 2007 3:54 am |
|
|
|
Guest
|
On 15 mai, 02:47, "Nasser Abbasi" <n...@12000.org> wrote:
Quote: I wanted to chat a little about this for sometime, but keep forgetting.
I think using Mathematica for linear algebra can be really confusing for
some one who is used to working with standard linear algebra conventions and
using tools such as Matlab.
To start with, Mathematica does not even have the concept of a row vs column
vector.
Secondly, what one would normally expect to be a column vector comes out to
be a row vector in Mathematica.
This is a simple example.
Given a matrix A, and we want to find its eigenvectors. Lets say it has 2
eigenvectors. Every where one looks, the eigenvectors are presented as
columns in the result. So the result of calling a function which returns
eigenvectors of a matrix is another matrix, whose *columns* are the
eigenvectors. This is the standard and 'common' way.
However, in Mathematica, things come out as lists within lists, and so when
one displays the matrix which contains the eigenvectors, the eigenvectors
are *rows* and not columns, because each list represents one eigenvector,
and each list is a row. This means when one is using Mathematica in this
example, one must remember to transpose the output to make it look as one is
'used' to seeing. Even the Mathematica help example on Eigenvector does a
Transpose on the result to make it look like the standard way.
Here is an example:
A = {{5, 20}, {20, 80}};
v = Eigenvectors[A]
Out[34]= {{1, 4}, {-4, 1}}
Notice that the first list is {1,4}, this is the first eigenvector. The
second list is the second eigenvector. Now when one displays this list of
lists as a matrix using MatrixForm[] to see it more clearly, the first
eigenvector is displayed as the first row, and the second as the second row.
v=[1 , 4 ]
[-4, 1 ]
Now if you show the above v matrix to any one who works in Linear Algebra
allot, and tells them this matrix contains the eigenvectors, I bet you that
99% of them will then say the first eigenvector is the first column and the
second eigenvector is the second column. Then they will be wrong. Because it
should be
v=[1 , -4]
[4 , 1]
This is not an earth shattering thing. In a way it like some languages start
the index at 0 and some at 1, and one can try to get used to it.
But I just wanted to point out, that the above can be confusing to someone
using Mathematica for LinearAlgbera for first time, because these things are
really important, i.e. columns and rows and things like that, for linear
algebra.
Thank you for listening.
Nasser
The same subject on comp.soft-sys.math.mathematica ten years ago :
Mathematica rather consistently works with row vectors rather than
column vectors. For example, Eigenvectors also returns row vectors.
I cannot comment on the design reasons for that. Of course there's a
dissonance with what's commonly done in many math books, but think of
how much screen space vectors would take if they always were formed
into vertical columns.
Of course, there is really no such thing as a row vector or a column
vector in Mathematica -- just lists. A simple list of scalars has an
interpretation as a row vector and, of course, displays horizontally
by default.
[...]
--
Murray Eisenberg
Mathematics & Statistics Dept.
University of Massachusetts
Amherst, MA 01003 |
|
|
| Back to top |
|
| Szabolcs |
Posted: Tue May 15, 2007 8:08 am |
|
|
|
Guest
|
Valeri Astanoff wrote:
Quote: The same subject on comp.soft-sys.math.mathematica ten years ago :
Mathematica rather consistently works with row vectors rather than
column vectors. For example, Eigenvectors also returns row vectors.
I cannot comment on the design reasons for that. Of course there's a
dissonance with what's commonly done in many math books, but think of
how much screen space vectors would take if they always were formed
into vertical columns.
Of course, there is really no such thing as a row vector or a column
vector in Mathematica -- just lists. A simple list of scalars has an
interpretation as a row vector and, of course, displays horizontally
by default.
[...]
I would like to add a small correction to this. Mathematica can deal
with 1, 2, 3, etc. dimensional tensors. For a 1D vector it does not make
sense to ask whether it is a row vector or column vector. You can only
have 1*n (row) or n*1 (column) *matrices*, but not vectors.
A non-nested List is interpreted as a 1D vector. A 2D matrix can be
multiplied by a vector both from the left or from the right, and the
result is a 1D vector. The MatrixForm formatting function displays a
non-nested List as a column. Matrices are represented as the List of
their row-vectors, and MatrixForm formats them accordingly.
The following series of calculations illustrate this:
In[1]:=
mat={{a,b},{c,d}}
Out[1]=
{{a, b}, {c, d}}
In[2]:=
mat//MatrixForm
Out[2]//MatrixForm=
a b
c d
In[3]:=
vec={x,y}
Out[3]=
{x, y}
In[4]:=
vec//MatrixForm
Out[4]//MatrixForm=
x
y
In[5]:=
mat.vec
Out[5]=
{a x + b y, c x + d y}
In[6]:=
%//MatrixForm
Out[6]//MatrixForm=
a x + b y
c x + d y
In[7]:=
vec.mat
Out[7]=
{a x + c y, b x + d y} |
|
|
| Back to top |
|
| |
|
Page 1 of 1
All times are GMT - 5 Hours
The time now is Tue Oct 07, 2008 2:08 am
|
|