Vector Operations in Computational Physics
Vector Operations in Computational Physics
1
Vector Operations
Vector Operations
Subtraction of vectors: Let 𝑎 and 𝑏
be two vectors. We define 𝑎-𝑏 as the
sum of the vector a and the vector (- 𝑏
). To subtract 𝑏 from 𝑎, invert the
direction of 𝑏 and add to 𝑎.
4
𝐴𝐶 2 = 𝐴𝐵2 + 𝐵𝐶 2 tan 𝜃 =
3
= 32 + 42 4
= 25 𝜃 = tan−1 ( )
3
AC = 5 𝜃 = 58°
Vector Operations
Home Work: Find the resultant of the three vectors shown in figure.
𝑖×𝑗= 𝑘 𝑖×𝑖=0
𝑗×𝑘 = 𝑖 𝑗×𝑗=0
𝑘×𝑖= 𝑗 𝑘×𝑘 =0
Vector Operations
Cross Product of Two Vectors in terms of the Components along the
Coordinate Axes:
Vector Operations
Example: The vector has 𝒂 magnitude of 5 unit, 𝒃 has a magnitude of 6 unit
and the cross product of 𝒂 and 𝒃 has a magnitude of 15 unit. Find the angle
between 𝒂 and 𝒃 .
Solution: If the angle between 𝒂 and 𝒃 is 𝜃, the cross product will have a
magnitude
𝐴 × 𝐵 = 𝐴𝐵 𝑆𝑖𝑛𝜃
15 = 5 × 6 𝑆𝑖𝑛𝜃
15
𝑆𝑖𝑛𝜃 =
30
1
𝑆𝑖𝑛𝜃 =
2
𝜃 = 30° 𝑜𝑟 150°
Vector Operations
Example: Write the unit vector in the direction of 𝐴 = 5𝑖 + 𝑗 − 2𝑘.
𝐴 = 52 + 12 + (−2)2 = 30
5 1 2
𝐴= 𝑖+ 𝑗− 𝑘.
30 30 30
Vector Operations
Example: If |𝑎 + 𝑏| = |𝑎 − 𝑏| show that 𝒂 𝒑𝒆𝒓𝒑𝒆𝒏𝒅𝒊𝒄𝒖𝒍𝒂𝒓 𝒕𝒐 𝒃
Vector Operations
Example: If 𝐴 = 2𝑖 − 3𝑗 + 7𝑘, 𝐵 = 𝑖 + 2𝑘, 𝑎𝑛𝑑 𝐶 = 𝑗 − 𝑘 find 𝐴. 𝐵 × 𝐶 .
Vector Operations
Triple product: Since the cross product of two vectors is a vector, it can be
dotted and crossed to form a triple product.
Scalar triple product: If we take a dot product with the resultant of vectors
B and C with another vector A.
𝐴. (𝐵 × 𝐶)
Geometrically, | 𝐴. (𝐵 × 𝐶) | is the
volume of parallelepiped generated by
vectors A, B, and C.
Because, | 𝐵 × 𝐶 | is the base
parallelepiped while |𝑨𝒄𝒐𝒔𝜽| is the
altitude.
Vector Operations
Triple product properties: (1) The scale triple product is unchanged under
the circular shift of vectors A, B, and, C.
𝑨. 𝑩 × 𝑪 = 𝑩. 𝑪 × 𝑨 = 𝑪. 𝑨 × 𝑩
(2) Swapping any two of the three operands negates the triple product
𝑨. 𝑩 × 𝑪 = - 𝑨. 𝑪 × 𝑩 = -𝑩. 𝑨 × 𝑪 = - 𝑪. 𝑩 × 𝑨
(3) The scalar triple product can also be understood as the determinant of
the 3×3 matrix that has the three vectors either as its rows or its columns.
𝐴𝑥 𝐴𝑦 𝐴𝑧
𝑨. 𝑩 × 𝑪 = 𝐵𝑥 𝐵𝑦 𝐵𝑧
𝐶𝑥 𝐶𝑦 𝐶𝑧
NOTE: 𝑨. 𝑩 × 𝑪 is meaningless.
Vector Operations
(4) If the scalar triple product is equal to zero, then the three vectors a, b,
and c are coplanar, since the parallelepiped defined by them would be flat
and have no volume.
𝑨. 𝑨 × 𝑪 = 𝑨. 𝑩 × 𝑨 = 𝑩. 𝑨 × 𝑨 = 𝟎
The simple product of two triple products (or the square of a triple product),
may be expanded in terms of dot products:
𝑨. 𝑫 𝑨. 𝑬 𝑨. 𝑭
(𝑨. (𝑩 × 𝑪))((𝑫. (𝑬 × 𝑭)) = 𝑩. 𝑫 𝑨. 𝑬 𝑩. 𝑭
𝑪. 𝑫 𝑨. 𝑬 𝑪. 𝑭
Vector Operations
Vector triple product: If we take a cross product with the resultant of
vectors B and C with another vector A. It can be simplified by BAC-CAB
𝑨 × 𝑩 × 𝑪 = 𝑩 𝑨. 𝑪 − 𝑪 𝑨. 𝑩
Please note that
𝑨 × 𝑩 × 𝑪 = −𝑪 × 𝑨 × 𝑩 = −𝑨 𝑩. 𝑪 + 𝑩 𝑨. 𝑪
Problem: Prove the BAC-CAB rule by writing out both sides in component
form.
The gradient has the formal appearance of a vector (i.e., del operator)
multiplying a scaler T.
The del is not a vector in the usual sense, and it is without specific meaning
until we provide it with a function to act upon. To be precise, we should
say del is vector operator that acts upon T, not a vector that multiplies T.
Divergence
From the definition of del operator, we can construct the
divergence
The divergence of a vector function is itself a scalar. You cant have the
divergence of the scaler, i.e., it is meaningless.
Divergence
Geometrical Interpretation
The name divergence is well chosen as it measures of much the vector v spreads
out (diverges) from the reference point in question.
Divergence
Numerical Problems
Calculate the divergence of these functions..
Divergence
Numerical Problems
Home Work: Estimate the divergence of the given functions.
Curl
Again, from the definition of del, we can
construct the curl
(2) Row Matrix: A matrix is said to be a row matrix if it has only one row.
1 B is a row matrix of
𝐵= − 5 2 3
2 order 1 × 4.
Matrix
Different types of matrix
(3) Square Matrix: A matrix in which the number of rows are equal to the
number of columns, is said to be a square matrix. Thus an m × n matrix is said
to be a square matrix if m = n and is known as a square matrix of order ‘n
3 −1 0
3 A is a square
𝐴= −3 2 1 matrix of order 3.
2
4 3 −1
3 0 0
−1 0
𝐴= 3 𝐵= C= 0 3 0
0 −1
0 0 3
𝑥 + 3 𝑧 + 4 2𝑦 − 7 0 6 3𝑦 − 2
𝐸𝑥𝑎𝑚𝑝𝑙𝑒: 𝐼𝑓 −6 𝑎−1 0 = −6 −3 2𝑐 + 2 , 𝑡ℎ𝑒𝑛 find
𝑏 − 3 −21 0 2𝑏 + 4 −21 0
the values of a, b, c, x, y, and z
Sol: As the given matrices are equal, therefore, their corresponding elements
must be equal. Comparing the corresponding elements, we get
𝒙+𝟑=𝟎 𝒂 − 𝟏 = −𝟑 𝒂 = −𝟐, 𝒃 = −𝟕, 𝒄 = −𝟏
𝒛+𝟒=𝟔 𝟎 = 𝟐𝒄 + 𝟐 𝒙 = −𝟑, 𝒚 = −𝟓, 𝒛 = 𝟐
𝟐𝒚 − 𝟕 = 𝟑𝒚 − 𝟐 𝒃 − 𝟑 = 𝟐𝒃 + 𝟒
Matrix
Sum of two matrix
𝟏 𝟐 𝟑 𝟑 −𝟏 𝟑
𝟐𝑨 − 𝑩 = 𝟐 −
𝟐 𝟑 𝟏 −𝟏 𝟎 𝟐
𝟐 𝟒 𝟔 −𝟑 𝟏 − 𝟑
= +
𝟒 𝟔 𝟐 𝟏 𝟎 −𝟐
−𝟏 𝟓 𝟑
=
𝟓 𝟔 𝟎
Matrix
Properties of matrix addition
(i) Commutative Law: If A = [aij], B = [bij] are matrices of the same order,
say m × n, then A + B = B + A.
(ii) Associative Law: For any three matrices A = [aij], B = [bij], C = [cij] of
the same order, say m × n, (A + B) + C = A + (B + C).
(iv) The existence of additive inverse: Let A = [aij] m × n be any matrix, then
we have another matrix as – A = [– aij] m × n such that A + (– A) = (– A) +
A= O. So – A is the additive inverse of A or negative of A.
Matrix
Matrix Multiplication: Firstly, we
can multiply the matrix by a scalar A,
it means k A where k is the scaler.
3 2
Example: If A and B =
1 4
3 2
1 4 then define AB and BA.
5 3
While BA is possible.
Matrix
6 9 2 6 0
Example: Find AB if A = and B =
2 3 7 9 8
In the above example, both AB and BA are of different order and so AB ≠ BA.
But one may think that perhaps AB and BA could be the same if they were of
the same order. But it is not so, here we give an example to show that even if
AB and BA are of the same order they may not be the same.
Matrix
1 0 0 1
Example: If A = and B = , then
0 −1 1 0
0 1
AB =
−1 0
0 −1
and BA =
1 0
Clearly AB ≠ BA.
Thus matrix multiplication is not commutative.
Matrix
The multiplication of matrices possesses the following properties
1. The associative law: For any three matrices A, B, and C. We have (AB)
C = A (BC), whenever both sides of the equality are defined.
3 2 3
For example: 𝐴= 2 −1.5 −1 is a symmetric matrix as A’ = A
3 −1 1
𝟐 −𝟐 −𝟒
Homework: Express the matrix A = −𝟏 𝟑 𝟒 as the sum of
𝟏 −𝟐 −𝟑
symmetric and skew-symmetric matrix.
Matrix
Invertible Matrix
If A is a square matrix of order m × m, and if there exists another square
matrix B of the same order m × m, such that AB = BA = I, then, A is said
to be an invertible matrix and B is called the inverse matrix of A and it is
denoted by A–1.
A rectangular matrix does not possess its inverse, since for the products BA
and AB to be defined and to be equal, matrices A and B must be square
matrices of the same order.
1 0
Also, BA = =𝐼
0 1
Thus B is the inverse of A and
A is the inverse of B.
Matrix
Matrix transformation
2 0 -2 0 1 0 2 0 -2 0 1 0
0 1 1 0 0 1 0 1 1 0 0 1
A I
1 0 -1 0 0.5 0 2 0 -2 0 1 0
0 1 1 0 0 1 0 1 1 0 0 1
R2 = R2/2 R1 = R1/5
Matrix
Inverse of Matrix:
0 1 1 0 0 1 0 1 1 0 0 1
R2 = R2-R1 R2 = R2+R3
1 0 0 0.2 0.2 0
Hence, the inverse of matrix is 0 1 0 -0.2 0.3 1
0.2 0.2 0
−0.2 0.3 1 0 0 1 0.2 -0.3 0
0.2 −0.3 0
R3 = R3-R2
Matrix
Different Method for the inverse of the matrix: We need adjoint of the matrix
(adj(A)) and determent of matrix A (det A).
𝑎𝑑𝑗 (𝐴)
Inverse of the matrix can also be calculated using 𝐴−1 =
|𝐴|
Matrix
Homework: Find the inverse of the given matrix A using adjoint and
determent of the matrix.
3 2 1
𝐴= 2 3 1
1 1 4
Matrix
A system of linear equations can be solved using the matrix inversion operation
Let the equations be
•All the variables in the equations should be written
𝑎1 𝑥 + 𝑎2 𝑦 + 𝑎3 𝑧 = 𝑑1 in the appropriate order.
𝑏1 𝑥 + 𝑏2 𝑦 + 𝑏3 𝑧 = 𝑑2 •The variables, their coefficients, and constants are
𝑐1 𝑥 + 𝑐2 𝑦 + 𝑐3 𝑧 = 𝑑3 to be written on the respective sides.
𝑨−𝟏 𝑨𝑿 = 𝑨−𝟏 𝑩
𝑰. 𝑿 = 𝑨−𝟏 𝑩
𝑿 = 𝑨−𝟏 𝑩
Matrix
Example: Solve the following
equations by matrix inversion
2𝑥 + 𝑦 + 2𝑧 = 0
2𝑥 − 𝑦 + 𝑧 = 10
𝑥 + 3𝑦 − 𝑧 = 5
Matrix
Example: Solve the following equations by matrix inversion
2𝑥 + 𝑦 + 2𝑧 = 0
2𝑥 − 𝑦 + 𝑧 = 10
𝑥 + 3𝑦 − 𝑧 = 5
Matrix
𝑥1
𝑥2
𝑋= .
.
𝑥𝑛
such that AX = λX , then the vector X is called an Eigenvector of A
corresponding to the Eigenvalue λ.
Matrix
Characteristic equation & Eigen Value
1 2
𝐴= & det(A-λI) = 0
0 2
1 2 1 0
𝑑𝑒𝑡 -λ =0
0 2 0 1
1−λ 2
𝑑𝑒𝑡 =0
0 2−λ
(1 − λ)(2 − λ)-0 = 0
𝝀𝟐 − 𝟑𝝀 + 𝟐 = 𝟎
λ−2 λ−1 =0
Hence, the eigenvalues (λ) are 2 and 1
Matrix
Characteristic equation
The characteristic equation of a 3x3 matrix is λ3 − 𝑆1 λ2 +𝑆2 𝜆 − 𝑆3 = 0
Where, S1= sum of main diagonal elements.
S2 = sum of minor of main diagonal elements.
S3 = Det (A) =|A|
The characteristic equation of a 2x2 matrix is λ2 − 𝑆1 λ+𝑆2 = 0
where, S1 = sum of main diagonal elements.
S2 = Det (A) =|A|
Matrix
Characteristic equation: Problem 1
1 2
𝐴=
0 2
The eigenvalues can be estimated using the roots of the quadratic equation.
−𝑏± 𝑏2 −4𝑎𝑐
λ= In the present case, a = 1, b = -3 and c =2.
2𝑎
When we put these values in the equation above, then the roots are
−(−𝟑) ± (−𝟑)𝟐 −𝟒 × 𝟏 × 𝟐
λ=
𝟐×𝟏
λ = 𝟐, 𝟏(𝑬𝒊𝒈𝒆𝒏 𝒗𝒂𝒍𝒖𝒆𝒔)
Matrix
Characteristic equation: Problem 2
2 −3 1
𝐴= 3 1 3
−5 2 −4
1 −1 4
𝐴 = 3 2 −1
2 1 −1
import numpy as np
M1 = [Link]([[3,6,9],[5,-10,5],[-7,14,21]])
M2 = [Link]([[9,-18,27],[11,22,33],[13,-26,39]])
M3 = M1+M2
print(“The sum matrix is ")
print(M3)
Matrix: Computers
Matrix Python: Difference of two matrices in Python.
import numpy as np
M1 = [Link]([[3,6,9],[5,-10,5],[-7,14,21]])
M2 = [Link]([[9,-18,27],[11,22,33],[13,-26,39]])
M3 = M1-M2
result = [Link](A,B)
Print(result)
for r in result:print(r)
Matrix: Computers
Matrix Python: Multiplication of two matrices in Python.
M1 = [Link]([[3, 6, 9], [5, -10, 15], [4,8,12]])
M2 = [Link]()
print(M1) #original matrix
print(M2) #Transpose matrix
Matrix: Computers
Matrix Python: inverse of a matrix in Python.
import numpy as np
A = [Link]([[6, 1, 1], [4, -2, 5], [2, 8, 7]])
B = [Link](A)
print (B)
Matrix: Computers
Matrix Python: built a matrix in Python, and component
of matrix
Matrix: Computers
Matrix Python: Sum of two matrices in Python.
Using the same method, we can determine the difference between the two
matrices. Only use a minus sign instead of a plus sign.
Matrix: Computers
Matrix Python: Multiplication of two matrices in Python.
for i in range(len(X)):
for j in range(len(X[0])):
result[j][i] = X[i][j]
2 -3 4
0 -1 1
A I
Matrices: Gauss-Jordan
Matrices: Gauss-
Jordan
3 3 4
2 -3 4
0 -1 1
Vectors opreations
Unit vector
Vectors operations
Vectors operations
Find the angle between side AC and side AB of a triangle ABC.
Coordinates of the vertices A,B,C are (1+2√3, 1, 2), (1, 1, 2), and
(1,3,2) respectively.
B (1, 1, 2)
A
(1+2√3, 1, 2)
C
(1,3,2)
Vectors operations
Vectors operations
Vectors operations
Find area vector and area that is orthogonal to the plane containing the
points P=(3,0,1), Q=(4,−2,1), and R=(5,3,−1).
Q (4,−2,1)
P (3,0,1)
R (5,3,−1)
Gradient, divergence and curl
f is scalar
Gradient, divergence
φ = x3yz3 and A = xz i – y2 j
and curl
+ 2x2y k
Evaluate
(a)❑φ
(b)❑. A
(c)❑x A
Integral
F = F x i + F y j + Fz k
d r =d x i+dy j+dz k
∫ F . d r = ∫ F x dx + F y dy+ F z dz
c c
W = ∫ F . d r = V (P 2 )−V (P1)
P1
W =∮ F. d r=0
F=−∇ V
∇ x F =0
Vectors: computer
import numpy as np
list1 = [1, 2, 3]
list2 = [[10],
[20],
[30]]
vector1 = [Link](list1) vector2 = [Link](list2)
Scalar quantities follow the rules of Vector quantity follows the rules of
ordinary algebra. vector algebra.