CoCalc Public Filespolarization tensors in detector's frame.ipynb
Author: Chan Park
Views : 160
Description: Polarization Tensors in Detector's Frame
Compute Environment: Ubuntu 18.04 (Deprecated)
In [1]:
%display latex

In [2]:
theta, phi, psi = var('theta, phi, psi')

In [3]:
R_z = matrix([[cos(x),-sin(x),0],[sin(x),cos(x),0],[0,0,1]])

In [4]:
R_y = matrix([[cos(x),0,sin(x)],[0,1,0],[-sin(x),0,cos(x)]])

In [5]:
R1 = R_z(x=phi); R1

$\left(\begin{array}{rrr} \cos\left(\phi\right) & -\sin\left(\phi\right) & 0 \\ \sin\left(\phi\right) & \cos\left(\phi\right) & 0 \\ 0 & 0 & 1 \end{array}\right)$
In [6]:
R2 = R_y(x=theta); R2

$\left(\begin{array}{rrr} \cos\left(\theta\right) & 0 & \sin\left(\theta\right) \\ 0 & 1 & 0 \\ -\sin\left(\theta\right) & 0 & \cos\left(\theta\right) \end{array}\right)$
In [7]:
R3 = R_z(x=psi); R3

$\left(\begin{array}{rrr} \cos\left(\psi\right) & -\sin\left(\psi\right) & 0 \\ \sin\left(\psi\right) & \cos\left(\psi\right) & 0 \\ 0 & 0 & 1 \end{array}\right)$
In [8]:
Lambda = R1*R2*R3; Lambda

$\left(\begin{array}{rrr} \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) - \sin\left(\phi\right) \sin\left(\psi\right) & -\cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\psi\right) - \cos\left(\psi\right) \sin\left(\phi\right) & \cos\left(\phi\right) \sin\left(\theta\right) \\ \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) + \cos\left(\phi\right) \sin\left(\psi\right) & -\cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) + \cos\left(\phi\right) \cos\left(\psi\right) & \sin\left(\phi\right) \sin\left(\theta\right) \\ -\cos\left(\psi\right) \sin\left(\theta\right) & \sin\left(\psi\right) \sin\left(\theta\right) & \cos\left(\theta\right) \end{array}\right)$
In [9]:
Lambda_inverse = R3(psi=-psi)*R2(theta=-theta)*R1(phi=-phi); Lambda_inverse.simplify_trig()

$\left(\begin{array}{rrr} \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) - \sin\left(\phi\right) \sin\left(\psi\right) & \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) + \cos\left(\phi\right) \sin\left(\psi\right) & -\cos\left(\psi\right) \sin\left(\theta\right) \\ -\cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\psi\right) - \cos\left(\psi\right) \sin\left(\phi\right) & -\cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) + \cos\left(\phi\right) \cos\left(\psi\right) & \sin\left(\psi\right) \sin\left(\theta\right) \\ \cos\left(\phi\right) \sin\left(\theta\right) & \sin\left(\phi\right) \sin\left(\theta\right) & \cos\left(\theta\right) \end{array}\right)$
In [10]:
(Lambda*Lambda_inverse).simplify_trig()

$\left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right)$
In [11]:
e = [
matrix([[1,0,0],[0,-1,0],[0,0,0]]),
matrix([[0,1,0],[1,0,0],[0,0,0]]),
matrix([[1,0,0],[0,1,0],[0,0,0]]),
matrix([[0,0,0],[0,0,0],[0,0,sqrt(2)]]),
matrix([[0,0,1],[0,0,0],[1,0,0]]),
matrix([[0,0,0],[0,0,1],[0,1,0]])
]; e

$\left[\left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 0 & 0 \end{array}\right), \left(\begin{array}{rrr} 0 & 1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 0 \end{array}\right), \left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 0 \end{array}\right), \left(\begin{array}{rrr} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & \sqrt{2} \end{array}\right), \left(\begin{array}{rrr} 0 & 0 & 1 \\ 0 & 0 & 0 \\ 1 & 0 & 0 \end{array}\right), \left(\begin{array}{rrr} 0 & 0 & 0 \\ 0 & 0 & 1 \\ 0 & 1 & 0 \end{array}\right)\right]$
In [12]:
e_bar = []
for i in range(6):
e_bar.append(Lambda*e[i]*Lambda_inverse)
show(e_bar[i].simplify_trig())

$\left(\begin{array}{rrr} -4 \, \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) - 2 \, {\left(2 \, \sin\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right)^{2} + {\left(2 \, {\left(\sin\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right)^{2} - \sin\left(\phi\right)^{2} + 1\right)} \sin\left(\theta\right)^{2} + 2 \, \sin\left(\phi\right)^{2} - 1 & 4 \, \cos\left(\phi\right) \cos\left(\psi\right)^{2} \sin\left(\phi\right) - 2 \, {\left(2 \, \sin\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\psi\right) - {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right)^{2} \sin\left(\phi\right) - \cos\left(\phi\right) \sin\left(\phi\right)\right)} \sin\left(\theta\right)^{2} - 2 \, \cos\left(\phi\right) \sin\left(\phi\right) & {\left(2 \, \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\psi\right) - {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right)^{2} - \cos\left(\phi\right)\right)} \cos\left(\theta\right)\right)} \sin\left(\theta\right) \\ 4 \, \cos\left(\phi\right) \cos\left(\psi\right)^{2} \sin\left(\phi\right) - 2 \, {\left(2 \, \sin\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\psi\right) - {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right)^{2} \sin\left(\phi\right) - \cos\left(\phi\right) \sin\left(\phi\right)\right)} \sin\left(\theta\right)^{2} - 2 \, \cos\left(\phi\right) \sin\left(\phi\right) & 4 \, \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) + 2 \, {\left(2 \, \sin\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right)^{2} - {\left(2 \, \cos\left(\psi\right)^{2} \sin\left(\phi\right)^{2} - \sin\left(\phi\right)^{2}\right)} \sin\left(\theta\right)^{2} - 2 \, \sin\left(\phi\right)^{2} + 1 & -{\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\psi\right) + {\left(2 \, \cos\left(\psi\right)^{2} \sin\left(\phi\right) - \sin\left(\phi\right)\right)} \cos\left(\theta\right)\right)} \sin\left(\theta\right) \\ {\left(2 \, \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\psi\right) - {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right)^{2} - \cos\left(\phi\right)\right)} \cos\left(\theta\right)\right)} \sin\left(\theta\right) & -{\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\psi\right) + {\left(2 \, \cos\left(\psi\right)^{2} \sin\left(\phi\right) - \sin\left(\phi\right)\right)} \cos\left(\theta\right)\right)} \sin\left(\theta\right) & {\left(2 \, \cos\left(\psi\right)^{2} - 1\right)} \sin\left(\theta\right)^{2} \end{array}\right)$
$\left(\begin{array}{rrr} -2 \, {\left(\sin\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} + 2 \, {\left(2 \, \sin\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \sin\left(\psi\right) + 2 \, {\left(2 \, \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\psi\right)^{2} - \cos\left(\phi\right) \sin\left(\phi\right)\right)} \cos\left(\theta\right) & 2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} - 4 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\psi\right) + {\left(2 \, {\left(2 \, \sin\left(\phi\right)^{2} - 1\right)} \sin\left(\psi\right)^{2} - 2 \, \sin\left(\phi\right)^{2} + 1\right)} \cos\left(\theta\right) & {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\psi\right) - 2 \, \sin\left(\phi\right) \sin\left(\psi\right)^{2} + \sin\left(\phi\right)\right)} \sin\left(\theta\right) \\ 2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} - 4 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\psi\right) + {\left(2 \, {\left(2 \, \sin\left(\phi\right)^{2} - 1\right)} \sin\left(\psi\right)^{2} - 2 \, \sin\left(\phi\right)^{2} + 1\right)} \cos\left(\theta\right) & 2 \, \cos\left(\psi\right) \sin\left(\phi\right)^{2} \sin\left(\psi\right) \sin\left(\theta\right)^{2} - 2 \, {\left(2 \, \sin\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \sin\left(\psi\right) - 2 \, {\left(2 \, \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\psi\right)^{2} - \cos\left(\phi\right) \sin\left(\phi\right)\right)} \cos\left(\theta\right) & {\left(2 \, \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) + 2 \, \cos\left(\phi\right) \sin\left(\psi\right)^{2} - \cos\left(\phi\right)\right)} \sin\left(\theta\right) \\ {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\psi\right) - 2 \, \sin\left(\phi\right) \sin\left(\psi\right)^{2} + \sin\left(\phi\right)\right)} \sin\left(\theta\right) & {\left(2 \, \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) + 2 \, \cos\left(\phi\right) \sin\left(\psi\right)^{2} - \cos\left(\phi\right)\right)} \sin\left(\theta\right) & -2 \, \cos\left(\psi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} \end{array}\right)$
$\left(\begin{array}{rrr} {\left(\sin\left(\phi\right)^{2} - 1\right)} \sin\left(\theta\right)^{2} + 1 & -\cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\theta\right)^{2} & -\cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\theta\right) \\ -\cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\theta\right)^{2} & -\sin\left(\phi\right)^{2} \sin\left(\theta\right)^{2} + 1 & -\cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\theta\right) \\ -\cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\theta\right) & -\cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\theta\right) & \sin\left(\theta\right)^{2} \end{array}\right)$
$\left(\begin{array}{rrr} \sqrt{2} \cos\left(\phi\right)^{2} \sin\left(\theta\right)^{2} & \sqrt{2} \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\theta\right)^{2} & \sqrt{2} \cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\theta\right) \\ \sqrt{2} \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\theta\right)^{2} & \sqrt{2} \sin\left(\phi\right)^{2} \sin\left(\theta\right)^{2} & \sqrt{2} \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\theta\right) \\ \sqrt{2} \cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\theta\right) & \sqrt{2} \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\theta\right) & \sqrt{2} \cos\left(\theta\right)^{2} \end{array}\right)$
$\left(\begin{array}{rrr} 2 \, {\left(\cos\left(\phi\right)^{2} \cos\left(\psi\right) \cos\left(\theta\right) - \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\psi\right)\right)} \sin\left(\theta\right) & {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) + {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \sin\left(\psi\right)\right)} \sin\left(\theta\right) & -2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\theta\right)^{2} - \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) + \cos\left(\phi\right) \cos\left(\psi\right) \\ {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) + {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \sin\left(\psi\right)\right)} \sin\left(\theta\right) & -2 \, {\left({\left(\cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \cos\left(\theta\right) - \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\psi\right)\right)} \sin\left(\theta\right) & -2 \, \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\theta\right)^{2} + \cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\psi\right) + \cos\left(\psi\right) \sin\left(\phi\right) \\ -2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\theta\right)^{2} - \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) + \cos\left(\phi\right) \cos\left(\psi\right) & -2 \, \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\theta\right)^{2} + \cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\psi\right) + \cos\left(\psi\right) \sin\left(\phi\right) & -2 \, \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\theta\right) \end{array}\right)$
$\left(\begin{array}{rrr} -2 \, {\left(\cos\left(\phi\right)^{2} \cos\left(\theta\right) \sin\left(\psi\right) + \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\phi\right)\right)} \sin\left(\theta\right) & -{\left(2 \, \cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) - {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right)\right)} \sin\left(\theta\right) & -2 \, \cos\left(\phi\right) \cos\left(\theta\right)^{2} \sin\left(\psi\right) - \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) + \cos\left(\phi\right) \sin\left(\psi\right) \\ -{\left(2 \, \cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) - {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right)\right)} \sin\left(\theta\right) & 2 \, {\left(\cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\phi\right) + {\left(\cos\left(\phi\right)^{2} - 1\right)} \cos\left(\theta\right) \sin\left(\psi\right)\right)} \sin\left(\theta\right) & -2 \, \cos\left(\theta\right)^{2} \sin\left(\phi\right) \sin\left(\psi\right) + \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) + \sin\left(\phi\right) \sin\left(\psi\right) \\ -2 \, \cos\left(\phi\right) \cos\left(\theta\right)^{2} \sin\left(\psi\right) - \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) + \cos\left(\phi\right) \sin\left(\psi\right) & -2 \, \cos\left(\theta\right)^{2} \sin\left(\phi\right) \sin\left(\psi\right) + \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) + \sin\left(\phi\right) \sin\left(\psi\right) & 2 \, \cos\left(\theta\right) \sin\left(\psi\right) \sin\left(\theta\right) \end{array}\right)$
In [13]:
a = matrix(SR, 6,6)
for i in range(6):
for j in range(6):
a[i,j] = sum(sum(e[i].elementwise_product(Lambda*e[j]*Lambda.transpose()/2))).simplify_trig()
a

$\left(\begin{array}{rrrrrr} -4 \, \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) + {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right)^{2} + \frac{1}{2} \, {\left(2 \, {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right)^{2} - 2 \, \cos\left(\phi\right)^{2} + 1\right)} \cos\left(\theta\right)^{2} - \cos\left(\phi\right)^{2} + \frac{1}{2} & {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} - 2 \, {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \sin\left(\psi\right) + 2 \, {\left(2 \, \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\psi\right)^{2} - \cos\left(\phi\right) \sin\left(\phi\right)\right)} \cos\left(\theta\right) & -\frac{1}{2} \, {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \sin\left(\theta\right)^{2} & \frac{1}{2} \, {\left(2 \, \sqrt{2} \cos\left(\phi\right)^{2} - \sqrt{2}\right)} \sin\left(\theta\right)^{2} & {\left({\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \cos\left(\theta\right) - 2 \, \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\psi\right)\right)} \sin\left(\theta\right) & -{\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\phi\right) + {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\theta\right) \sin\left(\psi\right)\right)} \sin\left(\theta\right) \\ -2 \, {\left(2 \, \sin\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\psi\right) - 4 \, \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\psi\right)^{2} + {\left(2 \, \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\psi\right)^{2} - \cos\left(\phi\right) \sin\left(\phi\right)\right)} \sin\left(\theta\right)^{2} + 2 \, \cos\left(\phi\right) \sin\left(\phi\right) & 2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} - 4 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\psi\right) + {\left(2 \, {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right)^{2} - 2 \, \cos\left(\phi\right)^{2} + 1\right)} \cos\left(\theta\right) & -\cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\theta\right)^{2} & \sqrt{2} \cos\left(\phi\right) \sin\left(\phi\right) \sin\left(\theta\right)^{2} & {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) + {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \sin\left(\psi\right)\right)} \sin\left(\theta\right) & -{\left(2 \, \cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) - {\left(2 \, \cos\left(\phi\right)^{2} - 1\right)} \cos\left(\psi\right)\right)} \sin\left(\theta\right) \\ -\frac{1}{2} \, {\left(2 \, \cos\left(\psi\right)^{2} - 1\right)} \sin\left(\theta\right)^{2} & \cos\left(\psi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} & \frac{1}{2} \, \cos\left(\theta\right)^{2} + \frac{1}{2} & \frac{1}{2} \, \sqrt{2} \sin\left(\theta\right)^{2} & \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\theta\right) & -\cos\left(\theta\right) \sin\left(\psi\right) \sin\left(\theta\right) \\ \frac{1}{2} \, \sqrt{2} {\left(2 \, \cos\left(\psi\right)^{2} - 1\right)} \sin\left(\theta\right)^{2} & -\sqrt{2} \cos\left(\psi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} & \frac{1}{2} \, \sqrt{2} \sin\left(\theta\right)^{2} & \cos\left(\theta\right)^{2} & -\sqrt{2} \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\theta\right) & \sqrt{2} \cos\left(\theta\right) \sin\left(\psi\right) \sin\left(\theta\right) \\ {\left(2 \, \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\psi\right) - {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right)^{2} - \cos\left(\phi\right)\right)} \cos\left(\theta\right)\right)} \sin\left(\theta\right) & {\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\psi\right) - 2 \, \sin\left(\phi\right) \sin\left(\psi\right)^{2} + \sin\left(\phi\right)\right)} \sin\left(\theta\right) & -\cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\theta\right) & \sqrt{2} \cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\theta\right) & -2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\theta\right)^{2} - \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) + \cos\left(\phi\right) \cos\left(\psi\right) & 2 \, \cos\left(\phi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} - \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) - \cos\left(\phi\right) \sin\left(\psi\right) \\ -{\left(2 \, \cos\left(\phi\right) \cos\left(\psi\right) \sin\left(\psi\right) + {\left(2 \, \cos\left(\psi\right)^{2} \sin\left(\phi\right) - \sin\left(\phi\right)\right)} \cos\left(\theta\right)\right)} \sin\left(\theta\right) & {\left(2 \, \cos\left(\psi\right) \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\psi\right) - 2 \, \cos\left(\phi\right) \cos\left(\psi\right)^{2} + \cos\left(\phi\right)\right)} \sin\left(\theta\right) & -\cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\theta\right) & \sqrt{2} \cos\left(\theta\right) \sin\left(\phi\right) \sin\left(\theta\right) & -2 \, \cos\left(\psi\right) \sin\left(\phi\right) \sin\left(\theta\right)^{2} + \cos\left(\phi\right) \cos\left(\theta\right) \sin\left(\psi\right) + \cos\left(\psi\right) \sin\left(\phi\right) & 2 \, \sin\left(\phi\right) \sin\left(\psi\right) \sin\left(\theta\right)^{2} + \cos\left(\phi\right) \cos\left(\psi\right) \cos\left(\theta\right) - \sin\left(\phi\right) \sin\left(\psi\right) \end{array}\right)$
In [14]:
T = Spherical('radius', ['inclination', 'azimuth'])

In [15]:
r = var('r')

In [16]:
T.transform(radius=r, azimuth=phi, inclination=theta)

$\left(r \cos\left(\phi\right) \sin\left(\theta\right), r \sin\left(\phi\right) \sin\left(\theta\right), r \cos\left(\theta\right)\right)$
In [17]:
# cm = colormaps.hsv
# def c(x,y):
#     return float((x+y+x*y)/15) % 1
# pol = ['+', 'cross', 'b', 'l', 'x', 'y']
# for j,k in [(0,0),(1,1),(2,2),(0,1),(1,2),(2,0)]:
#     for i in range(2):
#         print('polarization: '+pol[i]+', ('+str(j+1)+','+str(k+1)+') component')
#         show(plot3d(e_bar[i][j][k], (theta, 0, pi), (phi, 0, 2*pi), transformation=T, color=(c,cm)))

In [ ]: