```python
import numpy as np
import math
import sympy
import sympy as sp
from sympy import latex, Eq, IndexedBase, symbols, Idx, Indexed, Sum, S, diff, Array, tensorproduct, Matrix
from sympy.functions.special.tensor_functions import KroneckerDelta
import matplotlib.pyplot as plt
from sympy.vector import Vector, CoordSys3D, AxisOrienter, BodyOrienter, Del, curl, divergence, gradient, is_conservative, is_solenoidal, scalar_potential, Point, scalar_potential_difference
from sympy.physics.vector import ReferenceFrame
from sympy.vector import express
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
from IPython.display import display, display_latex
```


```python
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z = sympy.symbols('a:z')
a_1, a_2, a_3, b_1, b_2, b_3, c_1, c_2, c_3, d_1, d_2, d_3 = symbols('a_1 a_2 a_3 b_1 b_2 b_3 c_1 c_2 c_3 d_1 d_2 d_3')
alpha, beta, gamma, theta, phi, rho, omega = sympy.symbols('alpha beta gamma theta phi rho omega')
Alpha, Beta, Gamma, Theta, Phi, Rho, Omega = sympy.symbols('Alpha Beta Gamma Theta Phi Rho Omega')
```

## Setup


```python
sympy.init_printing()
np.set_printoptions(precision=3)
```

### Symbols

Cross product: ^  
Dot product: &  
Outer product: |


```python
a, b, c, d, e, f = symbols('a:f')
u1, u2, u3, v1, v2, v3 = symbols('u_1 u_2 u_3 v_1 v_2 v_3')
E = ReferenceFrame('E')
u = u1 * E.x + u2 * E.y + u3 * E.z
v = v1 * E.x + v2 * E.y + v3 * E.z
u
```

#### Dot Product


```python
u & v
```

#### Cross Product


```python
u ^ v
```

### Normalize


```python
u.normalize()
```

### Magnitude


```python
u.magnitude()
```


```python
N = CoordSys3D('N')
```


```python
v = 2 * N.i + N.j
v
```


```python
Vector.zero
```


```python
N.origin
```


```python
P = N.origin.locate_new('P', a*N.i + b*N.j + c*N.k)
Q = P.locate_new('Q', -b*N.j)
P
```


```python
P.position_wrt(Q)
```


```python
Q.express_coordinates(N)
```

#### Dyadics


```python
dyad = N.i.outer(N.k)
dyad
```


```python
A = CoordSys3D('A')
B = A.orient_new_axis('B', theta, A.k)
B
```




$\displaystyle CoordSys3D\left(B, \left( \left[\begin{matrix}\cos{\left(\theta \right)} & \sin{\left(\theta \right)} & 0\\- \sin{\left(\theta \right)} & \cos{\left(\theta \right)} & 0\\0 & 0 & 1\end{matrix}\right], \  \mathbf{\hat{0}}\right), CoordSys3D\left(A, \left( \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right], \  \mathbf{\hat{0}}\right)\right)\right)$




```python
axis_orienter = AxisOrienter(theta, A.k)
B = A.orient_new('B', axis_orienter)
B
```




$\displaystyle CoordSys3D\left(B, \left( \left[\begin{matrix}\cos{\left(\theta \right)} & \sin{\left(\theta \right)} & 0\\- \sin{\left(\theta \right)} & \cos{\left(\theta \right)} & 0\\0 & 0 & 1\end{matrix}\right], \  \mathbf{\hat{0}}\right), CoordSys3D\left(A, \left( \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right], \  \mathbf{\hat{0}}\right)\right)\right)$



#### Chain Rotations


```python
A = CoordSys3D('A')
body_orienter = BodyOrienter(a, b, c, 'XYZ')
B = A.orient_new('B', (axis_orienter, body_orienter)).subs(theta, 0)
B
```




$\displaystyle CoordSys3D\left(B, \left( \left[\begin{matrix}\cos{\left(b \right)} \cos{\left(c \right)} & \sin{\left(a \right)} \sin{\left(b \right)} \cos{\left(c \right)} + \sin{\left(c \right)} \cos{\left(a \right)} & \sin{\left(a \right)} \sin{\left(c \right)} - \sin{\left(b \right)} \cos{\left(a \right)} \cos{\left(c \right)}\\- \sin{\left(c \right)} \cos{\left(b \right)} & - \sin{\left(a \right)} \sin{\left(b \right)} \sin{\left(c \right)} + \cos{\left(a \right)} \cos{\left(c \right)} & \sin{\left(a \right)} \cos{\left(c \right)} + \sin{\left(b \right)} \sin{\left(c \right)} \cos{\left(a \right)}\\\sin{\left(b \right)} & - \sin{\left(a \right)} \cos{\left(b \right)} & \cos{\left(a \right)} \cos{\left(b \right)}\end{matrix}\right], \  \mathbf{\hat{0}}\right), CoordSys3D\left(A, \left( \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right], \  \mathbf{\hat{0}}\right)\right)\right)$



#### Use Multiple Orienters


```python
C = A.orient_new('C', (axis_orienter, body_orienter))
C
```




$\displaystyle CoordSys3D\left(C, \left( \left[\begin{matrix}- \sin{\left(c \right)} \sin{\left(\theta \right)} \cos{\left(b \right)} + \cos{\left(b \right)} \cos{\left(c \right)} \cos{\left(\theta \right)} & \left(- \sin{\left(a \right)} \sin{\left(b \right)} \sin{\left(c \right)} + \cos{\left(a \right)} \cos{\left(c \right)}\right) \sin{\left(\theta \right)} + \left(\sin{\left(a \right)} \sin{\left(b \right)} \cos{\left(c \right)} + \sin{\left(c \right)} \cos{\left(a \right)}\right) \cos{\left(\theta \right)} & \left(\sin{\left(a \right)} \sin{\left(c \right)} - \sin{\left(b \right)} \cos{\left(a \right)} \cos{\left(c \right)}\right) \cos{\left(\theta \right)} + \left(\sin{\left(a \right)} \cos{\left(c \right)} + \sin{\left(b \right)} \sin{\left(c \right)} \cos{\left(a \right)}\right) \sin{\left(\theta \right)}\\- \sin{\left(c \right)} \cos{\left(b \right)} \cos{\left(\theta \right)} - \sin{\left(\theta \right)} \cos{\left(b \right)} \cos{\left(c \right)} & \left(- \sin{\left(a \right)} \sin{\left(b \right)} \sin{\left(c \right)} + \cos{\left(a \right)} \cos{\left(c \right)}\right) \cos{\left(\theta \right)} - \left(\sin{\left(a \right)} \sin{\left(b \right)} \cos{\left(c \right)} + \sin{\left(c \right)} \cos{\left(a \right)}\right) \sin{\left(\theta \right)} & - \left(\sin{\left(a \right)} \sin{\left(c \right)} - \sin{\left(b \right)} \cos{\left(a \right)} \cos{\left(c \right)}\right) \sin{\left(\theta \right)} + \left(\sin{\left(a \right)} \cos{\left(c \right)} + \sin{\left(b \right)} \sin{\left(c \right)} \cos{\left(a \right)}\right) \cos{\left(\theta \right)}\\\sin{\left(b \right)} & - \sin{\left(a \right)} \cos{\left(b \right)} & \cos{\left(a \right)} \cos{\left(b \right)}\end{matrix}\right], \  \mathbf{\hat{0}}\right), CoordSys3D\left(A, \left( \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right], \  \mathbf{\hat{0}}\right)\right)\right)$



#### Get Rotation Matrix W.R.T


```python
B.rotation_matrix(A)
```




$\displaystyle \left[\begin{matrix}- \sin{\left(c \right)} \sin{\left(\theta \right)} \cos{\left(b \right)} + \cos{\left(b \right)} \cos{\left(c \right)} \cos{\left(\theta \right)} & \left(- \sin{\left(a \right)} \sin{\left(b \right)} \sin{\left(c \right)} + \cos{\left(a \right)} \cos{\left(c \right)}\right) \sin{\left(\theta \right)} + \left(\sin{\left(a \right)} \sin{\left(b \right)} \cos{\left(c \right)} + \sin{\left(c \right)} \cos{\left(a \right)}\right) \cos{\left(\theta \right)} & \left(\sin{\left(a \right)} \sin{\left(c \right)} - \sin{\left(b \right)} \cos{\left(a \right)} \cos{\left(c \right)}\right) \cos{\left(\theta \right)} + \left(\sin{\left(a \right)} \cos{\left(c \right)} + \sin{\left(b \right)} \sin{\left(c \right)} \cos{\left(a \right)}\right) \sin{\left(\theta \right)}\\- \sin{\left(c \right)} \cos{\left(b \right)} \cos{\left(\theta \right)} - \sin{\left(\theta \right)} \cos{\left(b \right)} \cos{\left(c \right)} & \left(- \sin{\left(a \right)} \sin{\left(b \right)} \sin{\left(c \right)} + \cos{\left(a \right)} \cos{\left(c \right)}\right) \cos{\left(\theta \right)} - \left(\sin{\left(a \right)} \sin{\left(b \right)} \cos{\left(c \right)} + \sin{\left(c \right)} \cos{\left(a \right)}\right) \sin{\left(\theta \right)} & - \left(\sin{\left(a \right)} \sin{\left(c \right)} - \sin{\left(b \right)} \cos{\left(a \right)} \cos{\left(c \right)}\right) \sin{\left(\theta \right)} + \left(\sin{\left(a \right)} \cos{\left(c \right)} + \sin{\left(b \right)} \sin{\left(c \right)} \cos{\left(a \right)}\right) \cos{\left(\theta \right)}\\\sin{\left(b \right)} & - \sin{\left(a \right)} \cos{\left(b \right)} & \cos{\left(a \right)} \cos{\left(b \right)}\end{matrix}\right]$



#### Rotate and Translate


```python
C = A.orient_new_axis('C', a, A.k, location=2*A.j)
C.position_wrt(A)
```

#### Express : Vector instances can be expressed in user defined systems using express.


```python
M = N.orient_new_axis('M', a, N.k)
v1 = N.i + N.j + N.k
express(v1, M)
```


```python
v = N.i + N.j + N.k
v.to_matrix(M)
```




$\displaystyle \left[\begin{matrix}\sin{\left(a \right)} + \cos{\left(a \right)}\\- \sin{\left(a \right)} + \cos{\left(a \right)}\\1\end{matrix}\right]$



### Scalar and Vector Fields and Base Scalar

potential field = $2x^2y$


```python
R = CoordSys3D('R')
electric_potential = 2*R.x**2 * R.y
electric_potential
```


```python
diff(electric_potential, R.x)
```


```python
v = R.x**2*R.i + 2*R.x*R.z*R.k
v
```

#### Gradient


```python
C = CoordSys3D('C')
delop = Del()
gradient_field = delop(C.x*C.y*C.z)
gradient_field
```


```python
gradient_field.doit()
```


```python
gradient(C.x*C.y*C.z)
```


```python
delop.gradient(C.x*C.y*C.z).doit()
```

#### Curl

##### Method 1


```python
delop = Del()
delop.cross(C.x*C.y*C.z*C.i)
```


```python
delop.cross(C.x*C.y*C.z*C.i).doit()
```

##### Method 2


```python
curl(C.x*C.y*C.z*C.i)
```

#### Divergence


```python
divergence(C.x*C.y*C.z*(C.i + C.j + C.k))
```


```python
delop.dot(C.x*C.y*C.z*(C.i + C.j + C.k)).doit()
```

#### Directional Derivative


```python
from sympy.vector import directional_derivative
directional_derivative(C.x*C.y*C.z, 3*C.i + 4*C.j + C.k)
```

#### Conservative Field
* Curl = 0 
* Irrotational 
* Conservation of Energy
* Gradient of some scalar field


```python
R = CoordSys3D('R')
field = R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
is_conservative(field)
```




    True




```python
curl(field)
```

#### Solenoidal Field
* Div = 0


```python
R = CoordSys3D('R')
field = R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
is_solenoidal(field)
```




    True




```python
divergence(field)
```

#### Scalar Potential Functions


```python
R = CoordSys3D('R')
conservative_field = 4*R.x*R.y*R.z*R.i + 2*R.x**2*R.z*R.j + 2*R.x**2*R.y*R.k
scalar_potential(conservative_field, R)
```


```python
R = CoordSys3D('R')
P = R.origin.locate_new('P', 1*R.i + 2*R.j + 3*R.k)
vectfield = 4*R.x*R.y*R.i + 2*R.x**2*R.j
scalar_potential_difference(vectfield, R, R.origin, P)
```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```

## CHAPTER 1


```python
#E = ReferenceFrame('E')
#E = CoordSys3D('E')
```


```python
E = CoordSys3D('E')
A = a_1*E.i + a_2*E.j + a_3 * E.k
B = b_1*E.i + b_2*E.j + b_3 * E.k
```


```python
A
```


```python
B
```


```python
A & B
```

### Dot/Inner Product Using Vector Lengths

$A.B \equiv \frac{1}{4} [(A + B)^2 - (A - B)^2]$


```python
1/4*((A + B).magnitude()**2 - (A - B).magnitude()**2).simplify()
```

### Metric Tensor

$g(A, B) \equiv A.B$

### Tensor Product $\otimes$
* Every second rank tensor can be expressed as a sum of tensor products

### Contraction

* $contraction(A \otimes B) \equiv A.B$
* Reduces the rank of a tensor by 2
*  If $T = A \otimes B + C \otimes D + ..., contraction(T) = A.B + C.D + ...$
* If T is a rank 3 tensor $A \otimes B \otimes C + E \otimes F \otimes G + . . . $, $1 \& 3contraction(A \otimes B \otimes C + E \otimes F \otimes G + . . .) \equiv (A . C)B + (E . G)F + . . . .$

### Exercise 1.1

Knowledge:
* $\frac{dp}{dt} = F$ = m$a$
* Lorentz force $F$ = q$(E + v \times B)$
* Lorentz force $F$ = q$E$ (Assumming no magnetic field)
* E = m$v^2$


```python
m, q, t, v, B, E, F = sympy.symbols('m q t v B E F')
```


```python
Energy = m * v**2
```


```python
rate = Energy / t
rate
```


```python
rate = rate.subs(m*v/t, F)
rate
```


```python
rate = rate.subs(F, q*E)
rate
```

### Exercise 1.2


```python

```


```python

```


```python

```


```python

```

### 1.5 Component Representation of Tensor Algebra


```python
p, R = sympy.symbols('\overline{p} R')
```


```python
a = sympy.Matrix([1, 2, 3])
```


```python

```


```python

```

### Exercise 1.6


```python
E = CoordSys3D('E')
E_ = E.orient_new_axis('\overline{E}', phi, E.k)
# A = E.i + E.j + E.k # To create an actual vector object that supports to_matrix([CoordSys3D]) to get the transformation matrix
#A.to_matrix(E)
#E_.position_wrt(E)
#E_.origin.express_coordinates(E)
#type(E_.origin)

T = E_.rotation_matrix(E) # Immutable dense matrix
T
```




$\displaystyle \left[\begin{matrix}\cos{\left(\phi \right)} & \sin{\left(\phi \right)} & 0\\- \sin{\left(\phi \right)} & \cos{\left(\phi \right)} & 0\\0 & 0 & 1\end{matrix}\right]$




```python

```


```python

```


```python

```


```python

```


```python

```


```python

```

142a11afa527b9fac29ff24f882af7d2e01918d2
ipynb
Jupyter Notebook
Modern Classical Physics.ipynb
Valentine-Efagene/Jupyter-Notebooks
91a1d98354a270d214316eba21e4a435b3e17f5d
MIT
Modern Classical Physics.ipynb
Valentine-Efagene/Jupyter-Notebooks
91a1d98354a270d214316eba21e4a435b3e17f5d
MIT
Modern Classical Physics.ipynb
Valentine-Efagene/Jupyter-Notebooks
91a1d98354a270d214316eba21e4a435b3e17f5d
MIT
Qwen/Qwen-72B
1. YES
2. YES