# Difference between matrix and determinant

## What is the difference between matrix and determinant?

Matrix is one of the most important and powerful tools in mathematics which has found applications for a very large number
of disciplines such as engineering, economics, statistics, physics, chemistry, biology, etc.
The theory of matrix is extensively used in the solution of applied business and industrial problems. A matrix is simply an ordered arrangement of elements, it is meaningless to assign a single numerical value to a matrix. Today, the subject of matrices is one of the most important and powerful tools in science which has found applications in a very large number of disciplines such as Engineering Data Science, Econometrics, Statistical tools, physics Research, Bioinformatics, chemistry formula, etc. The theory of matrices is extensively used in the solution of applied business and industrial problems.

### How to write linear equations into matrices?

Matrices is a rectangular arrangement of pq numbers(real or complex) into p horizontal rows and q vertical columns enclosed by []. such as p*q read as p by q and matrix order p*q.The numbers forming a matrix are called elements. The plural of matrices is called matrix.
Example 1.
A=[1 5 2] means matrices A has one row and 3 columns. This is also called the row matrix of order 1*3.
Example 2.
A=[
5
2] means matrices A has 3 rows and 1 column. This is also called the column matrix of order 3*1.

### How do write a matrix in python?

import numpy as np #Library
data = np.array([[12], [34], [56]])
data
array([[1, 2], [3, 4], [5, 6]])

### Null or Zero matrix

Null or Zero matrices are p*q whose entries are all zero called the p*q null or zero matrices.

### How do we write zero matrices in python?

np.zeros((6,6)) #Create 6*6 matrix
array([[0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.]])
6*6
rows=6
columns=6
number of element=6*6

### Square Matrix

Square matrices are a p*q if p=q. That is if it has the same number of columns as rows called the p*q square matrix.

### How do we write a square matrix in python?

square = np.arange(9).reshape((3,3))
square
```array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])```
`rows=3`
`columns=3`

### Identity Matrix and Unit Matrix:

If all its main diagonal entries are 1's and all other entries are 0's. An identity matrix of order q is denoted by Iq or more simply by me.
How do write a unit or identity matrix in python?

### How do we write an identity matrix in python?

import numpy as np
np.identity(4)
array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]])

### Diagonal Matrix:

A square matrix is said to be diagonal if each of its entries not falling on the main diagonal is zero.

### How do we write a square matrix in python?

np.diag(np.diag(square))
```array([[0, 0, 0],
[0, 4, 0],
[0, 0, 8]])```

### Scalar Matrix:

A diagonal matrix whose all the diagonal elements are equal is called a scalar matrix.

### How do we write a scalar matrix in python?

np.tri(352, dtype=int)
array([[1, 1, 1, 0, 0], [1, 1, 1, 1, 0], [1, 1, 1, 1, 1]])

### Triangular Matrix:

A square matrix is said to be an upper(lower) triangular matrix if all entries below(above) the main diagonal are zeros.

### How do we write a triangular matrix in python?

np.tri(352, dtype=int)
array([[1, 1, 1, 0, 0], [1, 1, 1, 1, 0], [1, 1, 1, 1, 1]])
np.tril([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1)
array([[ 0, 0, 0], [ 4, 0, 0], [ 7, 8, 0], [10, 11, 12]])

we can add two matrices only if they are the
same order.
The order of the sum of two matrices is
same as that of the two original matrices.

### How to add matrices in python?

import numpy as np
PYTHON CODE
x = np.array([-101])
y = np.array([-202])
X, Y = np.meshgrid(x, y)
X=
array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]])
Y=
array([[-2, -2, -2], [ 0, 0, 0], [ 2, 2, 2]])
X+Y=
array([[-3, -2, -1], [-1, 0, 1], [ 1, 2, 3]])

### Subtraction of Matrices

we can subtract two matrices only if they are
the same order.The order of the subtraction of two
matrices are the same as that of the two original
matrices.
X=
array([[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]])

Y=
array([[-2, -2, -2], [ 0, 0, 0], [ 2, 2, 2]])
X-Y=
array([[ 1, 2, 3], [-1, 0, 1], [-3, -2, -1]])

### Multiplication of Matrix

The product of AB of matrices A and B can be defined under the
a condition that the number of columns of A must be equal to the
a number of rows of B.
If the number of columns in matrix A does equal to the number
of rows in matrix B, we say that the matrices are the product AB.
Where in that order, A is the left factor called the prefactor and B is the
right factor called the post factor.
Using Python
import numpy as np
Matrix A
A = np.arange(17).reshape(23)
A
array([[1, 2, 3], [4, 5, 6]]
Matrix B
B = np.arange(17).reshape(32)
B
array([[1, 2], [3, 4], [5, 6]])
np.dot(A, B)
array([[22, 28], [49, 64]])
np.dot(B, A)
array([[ 9, 12, 15], [19, 26, 33], [29, 40, 51]]
AB is not equal BA

### Multiplication of a matrix by a scalar;

Let A be an m*n matrix and k be a real or a complex number. Then the
multiplication of A by k denoted by kA is the m*n matrix obtained by
multiplying by each entry of A by k. This operation is called scalar
multiplication.

### Transpose of Matrix

Let A be an mxn matrix. The transpose of A' is nXm matrix obtained from Aby
interchanging the rows and columns of A. Thus the first row of A is the first
column of A' the second of A is the second column And so on.

#### How to apply transpose matrix python?

import numpy as np
A = np.arange(9).reshape(33)
A
array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])

### Transpose matrix in python

np.transpose(A)
A'= array([[0, 3, 6], [1, 4, 7], [2, 5, 8]])
Orthogonal Matrix Python
A square matrix A is said to be orthogonal if AA '=A' A=I
Python Code
from scipy.stats import ortho_group
import NumPy as np
A = ortho_group.rvs(dim=3)
A
array([[ 0.97828663, 0.07750361, -0.19221984], [ 0.19251271, 0.00374541, 0.98128733], [-0.07677325, 0.99698504, 0.01125634]])
np.set_printoptions(suppress=True)
A.dot(A.T)
array([[ 1., 0., -0.], [ 0., 1., 0.], [-0., 0., 1.]])

### Symmetric and skew-symmetric matrices

A square matrix A=(aij) is said to be skew-symmetric if A'=-A,
or equivalently, if a(ij) = -a(ji) for each i and j.
Example-Every square matrix can be expressed uniquely as the sum of a
symmetric and a skew-symmetric matrix.
Solution:
Let A be a square matrix. we can write
A=1/2(A+A')+1/2(A-A')
=P+Q, Where P=1/2(A+A') and Q=1/2(A-A')
Now P'=[1/2(A+A')]'=1/2(A+A')=1/2[A'+(A')']
=1/2(A'+A)=1/2(A+A')=P
P is symmetric.
similarly, Q is skew-symmetric.
Hence A is expressible as the sum of a symmetric and a skew-symmetric matrix.

### Elementary Operations on Matrix

Elementary operations on the matrix are also called elementary transformations. Elementary operations can be classified as elementary row transformations
and elementary column transformations. Elementary operations are used to
find the inverse of an invertible matrix and solve the system of linear
equations. Some operations applied on the rows(columns) of a matrix are
called elementary row(column )operations:
1. Interchange of any two rows(columns)If ith row(column) is interchanged
with jth row(column), we write Ri interchange Rj(Ci interchange Cj).
2. Multiplying the elements of a row (column) by a non-zero scalar.
If the elements of an ith row(column) are multiplied by a non-zero scalar
k, we write Ri tends to k Ri(Ci tends to kCi).
3. Adding to the elements of a row(column), the constant times the
corresponding elements of another row(column). We write Ri tends Ri+kRj
(Ci tends Ci+kCj).
Whenever a matrix B can be obtained from matrix A by one or more elements
operations, we say that A and B are equivalent and write A~`B
Example: C=AB be a product of two matrices, Any elementary row(column)
operation on C is equivalent to applying the same row(column) operation
on A(B).

#### How to find A inverse by the use of elementary row operations?

Let A be a square matrix of order n. We may write :
A=AI
Now we apply elementary row operations successively on both side
of the above in a bid to obtain matrix B such that I =BA
Then A is invertible and A inverse equals B.

### Row reduction and Echelon Forms

A rectangular matrix is in echelon form if it has the following three properties:
1) All non-zero rows are above any rows of all zeros.
2) Each leading entry of a row is in a column to the right of the leading entry of the row above it.
3) All entries in a column below a leading entry are zeros.
If a matrix in echelon form satisfies the following additional conditions then it is in reduced echelon form:
4) The leading entry in each non-zero row is 1.
5) Each leading 1 is the only non-zero entry in its column.

An echelon matrix is one that is in echelon form (respectively, reduced echelon form). Property 2 says that the leading entries form an echelon pattern that moves down and to the right through the matrix. Property 3 is a simple consequence of property 2, but we include it for emphasis.

Determinants: is in the solution of the simultaneous
system of linear equations. If A is a square matrix,
then the determinant function associates with A exactly
one numerical value called the determinant. The use
of determinants is in a solution of a simultaneous
system of linear equations. It is denoted by |A|.

A...........................|A|
square matrix                 determinant of A

### How to find the value of a Determinant?

There is main them behind the simplification of a determinant lies in obtaining
the maximum possible number of zeros in a row(column) by using the some
properties and then expand the determinant by that row(column). We denoted the
1st, 2nd,3rd rows of determinant by R1, R2, R3 respectively and the 1st,2nd,3rd columns
by C1,C2,C3 respectively.
Example:
Find the value of the determinant of order 2
|6 -3|
|7 -2|
Sol. 6(-2)-7(-3)= -12+21=9

### Determinant of order n

If A is a square matrix of order n (n>2) then its determinant may be calculated by multiplying the entries of any row(or column) by their co-factor and summing the resulting products.

Minors and Cofactors
Minor of an element of a determinant. Let |A|=|a(ij)| be a determinant order n. The minor of aij, the element in the ith row, and j th column of A determinant that is left by deleting i th row and the j th column. It is denoted by Mij.

#### Cofactor of an element of a determinant

Let |A|=|aij| be a determinant of order n. The cofactor of aij, denoted by Cij or Aij is defined as (-1)power i+j Mij, where i+j is the sum of row number i and column number j in which the entry lies.

### System of Linear Equation

Consistent System of Equations: A given system of equations is said to be consistent if it has one or more solutions.
InconsistenceSystem of Equations: A given system of equations is said to be consistence if it has no solution.
Let AX=B be the given system of equations.
a) If | A| is not equal to 0, the system has a unique solution and consistency.
b) If |A|=0 and (adj)B is not equal to O then the given system has no solution and is inconsistent.
c) If |A|=0 and (adj)B=O then the system has infinitely many solutions.

### Method of solving non-homogeneous linear equation.

We can obtain this by applying some methods.
Matrix Inverse Method
Gauss Elimination Method
Cramer's Rule

### How to apply pandas code in the matrix?

pd.DataFrame(np.array([[1011], [2021]]))
Dataframe 2x2 matrix
0 1 0 10 11 1 20 21

### Dataframe in python

df1 = pd.DataFrame([pd.Series(np.arange(1015)),
pd.Series(np.arange(1520))])
df1
2x5 matrix
01234
01011121314
11516171819

#### Change variable matrix in python

df = pd.DataFrame(np.array([[1011], [2021]]),
columns=['a''b'])
df
ab
01011
12021

### How to change the row matrix variable in python?

#pandas code
df = pd.DataFrame(np.array([[01], [23]]),
columns=['c1''c2'],index=['r1''r2'])
df
c1c2
r101
r223

### How to arrange a series?

s1 = pd.Series(np.arange(161))
s2 = pd.Series(np.arange(6111))
pd.DataFrame({'c1': s1, 'c2': s2})
c1c2
016
127
238
349
4510

More PYTHON