0% found this document useful (0 votes)
48 views13 pages

List (Elements) Represents A List of Objects

List[elements] represents a list in Mathematica. Elements are the members of the list separated by commas. Vectors and matrices are represented as lists in Mathematica, with a vector being a simple list and a matrix being a list of vectors. There are built-in commands like Table and Array that can be used to generate vectors and matrices by specifying a function and range of indices.

Uploaded by

Ashwani Tanwar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views13 pages

List (Elements) Represents A List of Objects

List[elements] represents a list in Mathematica. Elements are the members of the list separated by commas. Vectors and matrices are represented as lists in Mathematica, with a vector being a simple list and a matrix being a list of vectors. There are built-in commands like Table and Array that can be used to generate vectors and matrices by specifying a function and range of indices.

Uploaded by

Ashwani Tanwar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

List [ elements ] represents a list of objects.

Elements represents the members of the list separated by commas.


List[elements] is equivalent to {elements}.
{1, 2, 3, 4} = List[1, 2, 3, 4]
List[2, 5, 6, 8]
{2, 5, 6, 8]
{2, 5, 6, 8}
{2, 5, 6, 8]
Vectors and Matrices
Vectors and matrices are represented as lists in Mathematica.
A vector is a simple list and a matrix is a list of vectors.
The elements of a vector or a matrix may be entered manually as a list or, more
conveniently, by the use of built-in commands.
Vectors
1- Table[expression, {i, n}] constructs an n-dimensional vector whose elements are
the values
of expression for i = 1, 2, 3,..., n.
2- Array[f, n] generates an n-dimensional vector whose elements are f[1], f[2], ... , f[n].
f is a function of one variable.
1 - Table[expression, {i, n}]
Table[i 1, {i, 5}]
{2, 3, 4, 5, 6]
Table[i^2, {i, 5}]
{1, 4, 9, 16, 25]
2 - Array[f, n]
f[x_] : x^3
Array[f, 5]
{1, 8, 27, 64, 125]
Clear[all]
f[x_] : x^2 1
Array[f, 5]
{0, 3, 8, 15, 24]
Matrices
1 - Table[expression, {i, m}, {j, n}] constructs an m n matrix whose elements are
the values
of expression for (i, j) = (1, 1),...,(m,n).
2 - Array[f, {m, n}] generates an m n matrix whose elements are f[1,1], ... , f[m,n].
f is a function of two variables.
Matrices
1 - Table[expression, {i, m}, {j, n}] constructs an m n matrix whose elements are
the values
of expression for (i, j) = (1, 1),...,(m,n).
2 - Array[f, {m, n}] generates an m n matrix whose elements are f[1,1], ... , f[m,n].
f is a function of two variables.
1 - Table[ expression, {i, m}, {j, n}]
Table[i j, {i, 3}, {j, 3}]
{{2, 3, 4], {3, 4, 5], {4, 5, 6]]
Table[i^2 j^3, {i, 3}, {j, 3}]
{{2, 9, 28], {5, 12, 31], {10, 17, 36]]
2 - Array[ f, {m, n} ]
f[x_, y_] : x y
Array[f, {3, 3}]
{{2, 3, 4], {3, 4, 5], {4, 5, 6]]
Clear[all]
Matrices are represented as lists, they may be viewed as matrices by using the
MatrixForm
command.
1 - MatrixForm [list]
2 - MatrixForm [ expression ]
3 - List // MatrixForm
4 - expression // MatrixForm
1 - MatrixForm [list]
MatrixForm[{{1, 2}, {2, 3}}]

1 2
2 3

Clear[all]
K {{2, 3}, {5, 6}}
{{2, 3], {5, 6]]
MatrixForm[K]

2 3
5 6

MatrixForm[{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}]
1 2 3
2 3 4
3 4 5
2 Matrices.nb
2 - MatrixForm [ expression ]
MatrixForm[Table[i j, {i, 3}, {j, 3}]]
2 3 4
3 4 5
4 5 6
M Table[i j 1, {i, 3}, {j, 3}]
{{1, 2, 3], {2, 3, 4], {3, 4, 5]]
MatrixForm[M]
1 2 3
2 3 4
3 4 5
f[x_, y_] : x y
MatrixForm[Array[f, {3, 3}]]
2 3 4
3 4 5
4 5 6
Clear[all]
3 - List // MatrixForm
{{1, 2, 3}, {2, 3, 4}, {3, 4, 5}} // MatrixForm
1 2 3
2 3 4
3 4 5
M {{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}
{{1, 2, 3], {2, 3, 4], {3, 4, 5]]
M // MatrixForm
1 2 3
2 3 4
3 4 5
4 - expression // MatrixForm
Table[i^2 j^3, {i, 3}, {j, 3}] // MatrixForm
2 9 28
5 12 31
10 17 36
Additionally, a matrix can be introduced via the menu
Insert Table / Matrix New. . .
Matrices.nb 3
Additionally, a matrix can be introduced via the menu
Insert Table / Matrix New. . .
1 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
Question - To generate a vector whose entries are the squares of the first five
consecutive integers,
We could simply enter them by hand.
Table[i^2, {i, 5}]
{1, 4, 9, 16, 25]
Table[i^2, {i, 5}] // MatrixForm
1
4
9
16
25
ADDITION OF MATRICES
M1 Table[i^2 / 4 1 2 j^3, {i, 3}, {j, 3}]

13
4
,
69
4
,
221
4
, {4, 18, 56],
21
4
,
77
4
,
229
4

M1 // MatrixForm
13
4
69
4
221
4
4 18 56
21
4
77
4
229
4
M2 Table[i j, {i, 3}, {j, 3}]
{{2, 3, 4], {3, 4, 5], {4, 5, 6]]
4 Matrices.nb
M2 // MatrixForm
2 3 4
3 4 5
4 5 6
M1 M2 // MatrixForm
21
4
81
4
237
4
7 22 61
37
4
97
4
253
4
ADDITION OF MATRICES
M1 M2 // MatrixForm
5
4
57
4
205
4
1 14 51
5
4
57
4
205
4
ROW BY COLUMN MULTIPLICATION
M1.M2 // MatrixForm
1117
4
355
1723
4
286 364 442
1189
4
379
1843
4
ROW BY ROW CORRESPONDING ELEMENT MULTIPLICATION
M1 M2 // MatrixForm
13
2
207
4
221
12 72 280
21
385
4
687
2
DETERMINANT OF A MATRICES
Det[M1]
0
Det[M1.M2]
0
INVERSE OF A MATRIX
K {{1, 2, 3}, {8, 5, 2}, {6, 7, 9}}
{{1, 2, 3], {8, 5, 2], {6, 7, 9]]
Matrices.nb 5
K // MatrixForm
1 2 3
8 5 2
6 7 9
Det[K]
11
Inverse[K] // MatrixForm

31
11

3
11
1
60
11
9
11
2

26
11

5
11
1
TRANSPOSE OF A MATRIX
Transpose[K] // MatrixForm
1 8 6
2 5 7
3 2 9
RANK OF A MATRIX
MatrixRank[K]
3
EIGEN VALUES OF A MATRIX
Eigenvalues[M1]

1
4
157 27241 ,
1
4
157 27241 , 0
Eigenvalues[M2]
6 42 , 6 42 , 0
EIGEN VECTORS OF A MATRIX
Eigenvectors[M1]
__
2063
553

8
553
]157 27241 ,
1082
553

5
553
]157 27241 , 1_,
_
2063
553

8
553
]157 27241 ,
1082
553

5
553
]157 27241 , 1_, _
19
7
,
26
7
, 1__
Eigenvectors[M2] // N
{{0.612422, 0.806211, 1.], {1.38165, 0.190826, 1.], {1., 2., 1.]]
EIGEN VALUES AND VECTORS OF A MATRIX
{vals, vecs} Eigensystem[M1] // N
{{80.5121, 2.01212, 0.],
{{0.928369, 0.95523, 1.], {3.84699, 2.02937, 1.], {2.71429, 3.71429, 1.]]]
6 Matrices.nb
POWER OF A MATRIX
MatrixPower[K, 2] // MatrixForm
35 33 34
60 55 52
116 110 113
CHARACTERISTIC POLYNOMIAL OF A MATRIX
To find the Characteristic Polynomial of a matrix we will use following formulas.
1 - CharacteristicPolynomial [ Matrix, x ],
2 - Det [ Matrix - x*Identity[n] ]
1 - CharacteristicPolynomial [ Matrix, x ]
CharacteristicPolynomial [ M1, x ]
162 x
157 x
2
2
x
3
162 x
157 x
2
2
x
3
162 x
157 x
2
2
x
3
CharacteristicPolynomial [ M1, x ] // N
162. x 78.5 x
2
1. x
3
CharacteristicPolynomial [ M2, x ]
6 x 12 x
2
x
3
CharacteristicPolynomial [ K, x ]
11 11 x 15 x
2
x
3
2 - Det [ Matrix - x*Identity[n] ]
A - x*I
Det[K x IdentityMatrix[3]]
11 11 x 15 x
2
x
3
Matrices.nb 7
CHARACTERISTIC EQUATION & ITS SOLUTION OF A MATRIX
To find the Characteristic Equation & its solution of a matrix we will use following formulas.
1 - CharacteristicPolynomial [ Matrix, x ] == 0,
Solve[ % ]
2 - Det [ Matrix - x*Identity[n] ] == 0
Solve[ % ]
CharacteristicPolynomial [ M1, x ] 0
162 x
157 x
2
2
x
3
0
Solve[]
{x 0], x
1
4
157 27241 , x
1
4
157 27241
// N
{{x 0.], {x 2.01212], {x 80.5121]]
Det[K x IdentityMatrix[3]] 0
11 11 x 15 x
2
x
3
0
Solve[]
x 5
2
3
2/3
207 6303
1/3

32

3
2
207 6303
1/3
,
x 5
1 3
1
2
207 6303
1/3
3
2/3

16 1 3

3
2
207 6303
1/3
,
x 5
1 3
1
2
207 6303
1/3
3
2/3

16 1 3

3
2
207 6303
1/3

// N
{{x 14.1689 0. ], {x 1.38976 0. ], {x 0.558621 0. ]]
N[, 10]
{{x 14.1689 0. ], {x 1.38976 0. ], {x 0.558621 0. ]]
CHARACTERISTIC POLYNOMIAL
Let A =
1 0 2
0 2 1
2 0 3
Characteristic Matrix = A - I
=
1 0 2
0 2 1
2 0 3
-
1 0 0
0 1 0
0 0 1
=
1 0 2
0 2 1
2 0 3
Characteristic Polynomial = A - I
= 2 7 6
2

3
Characteristic Equation
A - I = 0
2 7 6
2

3
= 0
8 Matrices.nb
CHARACTERISTIC POLYNOMIAL
Let A =
1 0 2
0 2 1
2 0 3
Characteristic Matrix = A - I
=
1 0 2
0 2 1
2 0 3
-
1 0 0
0 1 0
0 0 1
=
1 0 2
0 2 1
2 0 3
Characteristic Polynomial = A - I
= 2 7 6
2

3
Characteristic Equation
A - I = 0
2 7 6
2

3
= 0

Cayley-Hamilton theorem
the Cayley-Hamilton theorem says that, "every square matrix
satisfies its characteristic equation".
i.e For the matrix A and according to cayley-Hamilton's Theorem
we have -2I - 7A + 6 A
2
- A
3
= 0
Here I is an Identity matrix and 0 is a null matrix.
Question:- Verify the Cayley-Hamilton theorem for
A =
1 2 1
3 1 3
2 5 7

A {{1, 2, 1}, {3, 1, 3}, {2, 5, 7}}
{{1, 2, 1], {3, 1, 3], {2, 5, 7]]
MatrixForm[A]
1 2 1
3 1 3
2 5 7

CharacteristicPolynomial[A, x]
35 24 x 7 x
2
x
3

Matrices.nb 9
CharacteristicPolynomial[A, x] 0
35 24 x 7 x
2
x
3
0

35 IdentityMatrix[3] 24 A 7 MatrixPower[A, 2] MatrixPower[A, 3] // MatrixForm
0 0 0
0 0 0
0 0 0

SYSTEM OF LINEAR EQUATIONS
Q-1 The system
2 x + y + z = 7,
x 4 y + 3 z = 2,
3 x + 2 y + 2 z = 13 has a unique solution.

Clear[all]
Solve[{7 2 x y z 0, 2 x 4 y 3 z 0, 13 3 x 2 y 2 z 0}]
{{x 1, y 2, z 3}}
{{x 1, y 2, z 3]]
OR

LinearSolve[{{2, 1, 1}, {1, 4, 3}, {3, 2, 2}}, {7, 2, 13}]
{1, 2, 3]
Q-2 The system
2 x + y + z = 7,
x 4 y + 3 z = 2,
3 x 3 y + 4 z = 13 has no solution.

Solve[{7 2 x y z 0, 2 x 4 y 3 z 0, 13 3 x 3 y 4 z 0}]
{]
OR

LinearSolve[{{2, 1, 1}, {1, 4, 3}, {3, 3, 4}}, {7, 2, 13}]
LinearSolve::nosol : Linear equation encountered that has no solution.
LinearSolve[{{2, 1, 1], {1, 4, 3], {3, 3, 4]], {7, 2, 13]]
Q-3 The system
2 x + y + z = 7,
x 4 y + 3 z = 2,
3 x 3 y + 4 z = 9 has infinitely many solution.

10 Matrices.nb
Solve[{7 2 x y z 0, 2 x 4 y 3 z 0, 9 3 x 3 y 4 z 0}]
Solve::svars : Equations may not give solutions for all "solve" variables.
x
10
3

7 z
9
, y
1
3

5 z
9

OR

LinearSolve[{{2, 1, 1}, {1, 4, 3}, {3, 3, 4}}, {7, 2, 9}]

10
3
,
1
3
, 0
/. z 1

10
3
,
1
3
, 0
BY USING MATRIX METHOD
A X = B

Clear[all]
A1 {{2, 1, 1}, {1, 4, 3}, {3, 2, 2}}
{{2, 1, 1], {1, 4, 3], {3, 2, 2]]
MatrixForm[A1]
2 1 1
1 4 3
3 2 2

B1 {7, 2, 13}
{7, 2, 13]
MatrixForm[B1]
7
2
13

LinearSolve[A1, B1]
{1, 2, 3]
A2 {{2, 1, 1}, {1, 4, 3}, {3, 3, 4}}
{{2, 1, 1], {1, 4, 3], {3, 3, 4]]
MatrixForm[A2]
2 1 1
1 4 3
3 3 4

Matrices.nb 11
B2 {7, 2, 13]
{7, 2, 13]
MatrixForm[B2]
7
2
13

LinearSolve[A2, B2]
LinearSolve::nosol : Linear equation encountered that has no solution.
LinearSolve[{{2, 1, 1], {1, 4, 3], {3, 3, 4]], {7, 2, 13]]
If the system A.X = B has an infinite number of solutions, the treatment is a bit more
complicated.
In this case, Mathematica returns one solution, known as a particular solution.
The full set of solutions is constructed by adding to the particular solution
in the set of all solutions of the corresponding homogeneous system, A.X = 0.
The set of all vectors, x, such that AX = 0,
is called the null space of a and is easily determined by the command NullSpace.
NullSpace[A] returns the basis vectors of the null space of A.
The nullity of A, the dimension of the null space of a, can be found by computing
Length[NullSpace[A]].
The full set of solutions to the system is of the form
t*nullspacebasis + particular
where t is an arbitrary parameter.

A3 {{2, 1, 1}, {1, 4, 3}, {3, 3, 4}}
{{2, 1, 1], {1, 4, 3], {3, 3, 4]]
MatrixForm[A3]
2 1 1
1 4 3
3 3 4

B3 {7, 2, 9]
{7, 2, 9]
MatrixForm[B3]
7
2
9

NullSpaceof NullSpace[A3]
{{7, 5, 9]]
12 Matrices.nb
Particular LinearSolve[A3, B3]

10
3
,
1
3
, 0
GeneralSolution t Flatten[NullSpaceof] Particular

10
3
7 t,
1
3
5 t, 9 t
/. t 1

11
3
,
16
3
, 9
31 /. t 2

32
3
,
31
3
, 18
GeneralSolution /. t 5

95
3
,
76
3
, 45
Matrices.nb 13

You might also like