Mathematical Statistics with Mathematica,
Colin Rose and Murry D. Smith
Appendix A.7 Working with Vectors
Colin Rose and Murry D. Smith
Appendix A.7 Working with Vectors
Working with Vectors
Working with Vectors
Thre are two completely different ways to enter a vector in Mathematica.
1
.The List Approach: This is the standard Mathematica method. It does not distinguish between column and row vectors. Thus, Transpose cannot be used on these vectors.
2
.The Matrix Approach: Here, a vector is entered as a special case of a matrix. This deoes distingushe between column and row vectors, so Transpose can be used with these vectors, Entering the vector this way takes more effort, but it can be less confusing and more ‘natural’ than the List approach.
Mixing the two approaches is not recommended, as this may cause error and confusion.
Vectors
Vectors
thecolumnvectorandtherowvector
(3x1)
v
(1x3)
u
u
|
the List approach
v={a,b,c}u={1,2,3}
{a,b,c}
{1,2,3}
the matrix approach
(vcol={{a},{b},{c}})//MatrixForm(urow={{1,2,3}})//MatrixForm
a |
b |
c |
(
)
1 | 2 | 3 |
Tvv(1x1)
T
v
v
the List approach
v.v
2
a
2
b
2
c
the matrix approach
Transpose[vcol].vcol
{{++}}
2
a
2
b
2
c
Transpose[vcol].vcol//Part[#,1,1]&
2
a
2
b
2
c
uTu(1x1)
u
T
u
the List approach
u.u
14
the matrix approach
urow.Transpose[urow]
{{14}}
urow.Transpose[urow]//Part[#,1,1]&
14
vTv(3x3)
v
T
v
the List approach
Outer[Times,v,v]//MatrixForm
2 a | ab | ac |
ab | 2 b | bc |
ac | bc | 2 c |
the matrix approach
vcol.Transpose[vcol]//MatrixForm
2 a | ab | ac |
ab | 2 b | bc |
ac | bc | 2 c |
Tuu(3x3)
T
u
u
the List approach
Outer[Times,u,u]//MatrixForm
1 | 2 | 3 |
2 | 4 | 6 |
3 | 6 | 9 |
the matrix approach
Transpose[urow].urow//MatrixForm
1 | 2 | 3 |
2 | 4 | 6 |
3 | 6 | 9 |
Now Suppose :
Now Suppose :
(M={{1,0,0},{4,5,6},{0,0,9}})//MatrixForm
1 | 0 | 0 |
4 | 5 | 6 |
0 | 0 | 9 |
TvMv(1x1)
T
v
v
the List approach
v.M.v
5+a(a+4b)+c(6b+9c)
2
b
the matrix approach
Transpose[vcol].M.vcol
{{5+a(a+4b)+c(6b+9c)}}
2
b
Transpose[vcol].M.vcol//Part[#,1,1]&
5+a(a+4b)+c(6b+9c)
2
b
TuMu(3x3)
T
u
u
the List approach
u.M.u
146
the matrix approach
urow.M.Transpose[urow]
{{146}}
urow.M.Transpose[urow]//Part[#,1,1]&
Grad
Grad
the List approach
the matrix approach
Grad
the List approach
the matrix approach