Skip to content

Commit

Permalink
commit only inverse_of_matrices.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
astellhorn committed Jul 15, 2024
1 parent 44aeafc commit bb4dc9e
Showing 1 changed file with 286 additions and 14 deletions.
300 changes: 286 additions & 14 deletions docs/user-guide/inverse_of_polarization_matrices.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"metadata": {},
"outputs": [],
"source": [
"import sympy as sp"
"import sympy as sp\n",
"import numpy as np"
]
},
{
Expand All @@ -18,7 +19,8 @@
"outputs": [],
"source": [
"Tp = sp.symbols('T^p_+, T^p_-', positive=True)\n",
"Ta = sp.symbols('T^a_+, T^a_-', positive=True)"
"Ta = sp.symbols('T^a_+, T^a_-', positive=True)\n",
"I = sp.symbols('Ipp, Ipm, Imp, Imm', positive=True)\n"
]
},
{
Expand All @@ -31,6 +33,19 @@
"From https://www.epj-conferences.org/articles/epjconf/abs/2023/12/epjconf_ecns2023_03004/epjconf_ecns2023_03004.html"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d6cda4a6",
"metadata": {},
"outputs": [],
"source": [
"I = sp.ImmutableDenseMatrix([\n",
" [I[0]], [I[1]], [I[2]], [I[3]]]\n",
")\n",
"I"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -146,13 +161,13 @@
"outputs": [],
"source": [
"f1, f2 = sp.symbols('f_1:3')\n",
"F1 = sp.ImmutableDenseMatrix([\n",
"F1_parallel = sp.ImmutableDenseMatrix([\n",
" [1, 0, 0, 0],\n",
" [0, 1, 0, 0],\n",
" [1-f1, 0, f1, 0],\n",
" [0, 1-f1, 0, f1],\n",
"])\n",
"F1"
"F1_parallel"
]
},
{
Expand All @@ -162,23 +177,65 @@
"metadata": {},
"outputs": [],
"source": [
"F1.inv()"
"F1_parallel.inv()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6a91128d-4da4-4fee-9cda-ceef4fc65dc6",
"id": "52a4390a",
"metadata": {},
"outputs": [],
"source": [
"F2 = sp.ImmutableDenseMatrix([\n",
"(F1_parallel.inv()@F1_parallel).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d06f20a5",
"metadata": {},
"outputs": [],
"source": [
"F2_parallel = sp.ImmutableDenseMatrix([\n",
" [1, 0, 0, 0],\n",
" [1-f2, f2, 0, 0],\n",
" [0, 0, 1, 0],\n",
" [0, 0, 1-f2, f2],\n",
"])\n",
"F2"
"F2_parallel"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "abe1231b",
"metadata": {},
"outputs": [],
"source": [
"F1_antiparallel = sp.ImmutableDenseMatrix([\n",
" [f1, 0, 1-f1, 0],\n",
" [0, f1, 0, 1-f1],\n",
" [0, 0, 1, 0],\n",
" [0, 0, 0, 1],\n",
"])\n",
"F1_antiparallel"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6a91128d-4da4-4fee-9cda-ceef4fc65dc6",
"metadata": {},
"outputs": [],
"source": [
"F2_antiparallel = sp.ImmutableDenseMatrix([\n",
" [1, 1-f2, 0, 0],\n",
" [0, f2, 0, 0],\n",
" [0, 0, 1, 1-f2],\n",
" [0, 0, 0, f2],\n",
"])\n",
"F2_antiparallel"
]
},
{
Expand All @@ -188,17 +245,232 @@
"metadata": {},
"outputs": [],
"source": [
"F2.inv()"
"(F1_antiparallel@F1_antiparallel.inv()).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "02053837",
"metadata": {},
"outputs": [],
"source": [
"(F2_antiparallel@F2_antiparallel.inv()).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f6e8bd1e",
"metadata": {},
"outputs": [],
"source": [
"(TP.inv()@F1_parallel.inv()).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa98ea5e",
"metadata": {},
"outputs": [],
"source": [
"(TP.inv()@F1_antiparallel.inv()).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc24aa41",
"metadata": {},
"outputs": [],
"source": [
"(F2_parallel.inv()@TA.inv()).simplify()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5308f9fe",
"metadata": {},
"outputs": [],
"source": [
"(F2_antiparallel.inv()@TA.inv()).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "76c6eac3",
"metadata": {},
"outputs": [],
"source": [
"(((F2_parallel.inv()@TA.inv())@I)*(Ta[0]**2 - Ta[1]**2)).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "03331c5a",
"metadata": {},
"outputs": [],
"source": [
"(((TP.inv()@F1_parallel.inv())@I)*(Tp[0]**2 - Tp[1]**2)).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aa92aba8",
"metadata": {},
"outputs": [],
"source": [
"(TP.inv() @ F1_parallel.inv() @ F2_parallel.inv() @ TA.inv()).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "696520c3",
"metadata": {},
"outputs": [],
"source": [
"(TP.inv() @ F1_antiparallel.inv() @ F2_antiparallel.inv() @ TA.inv()).simplify()"
]
},
{
"cell_type": "markdown",
"id": "18833019",
"metadata": {},
"source": [
"Now we will test if the flipper matrices together with the polarizer/analyzer matrices yield physically useful results for the examples:<br> \n",
"(i) collinear magnetic moments & no chiral terms, i.e., P=F=1 & S+-=S-+ <br>\n",
"(ii) chiral magnetic moments with S++=S--=0 & S+- \\neq S-+"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f218252",
"metadata": {},
"outputs": [],
"source": [
"S_test_i = sp.symbols('Spp, Spm, Smp, Smm', positive=True)\n",
"S_test_i = sp.ImmutableDenseMatrix([\n",
" [0], [S_test_i[1]], [S_test_i[2]], [0]]\n",
")\n",
"S_test_i"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "94b13485",
"metadata": {},
"outputs": [],
"source": [
"((TA @ F2_parallel @ F1_parallel @ TP)@S_test_i).simplify()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3c7805b4",
"metadata": {},
"outputs": [],
"source": [
"S_test_ii = sp.symbols('Spp, Spm, Smp, Smm', positive=True)\n",
"S_test_ii = sp.ImmutableDenseMatrix([\n",
" [S_test_ii[0]], [S_test_ii[1]], [S_test_ii[1]], [S_test_ii[3]]]\n",
")\n",
"S_test_ii"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5df7393b",
"metadata": {},
"outputs": [],
"source": [
"((TA @ F2_antiparallel)@S_test_ii).simplify()"
]
},
{
"cell_type": "markdown",
"id": "2ffcb6ef",
"metadata": {},
"source": [
"Now trying the same with the to 2-dim converted matrices"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1b218e9e",
"metadata": {},
"outputs": [],
"source": [
"S_test_iii = ([\n",
" [0], [4], [5], [0]]\n",
")\n",
"f1_test = 0.9\n",
"f2_test = 0.9\n",
"F1_parallel_test = np.array([\n",
" [1, 0, 0, 0],\n",
" [0, 1, 0, 0],\n",
" [1-0.9, 0, 0.9, 0],\n",
" [0, 1-0.9, 0, 0.9],\n",
"])\n",
"F2_parallel_test = np.array([\n",
" [1, 0, 0, 0],\n",
" [1-0.9, 0.9, 0, 0],\n",
" [0, 0, 1, 0],\n",
" [0, 0, 1-0.9, 0.9],\n",
"])\n",
"Tp_test = np.array([0.8, 0.2])\n",
"TP_test = np.array([\n",
" [Tp_test[0], 0, Tp_test[1], 0],\n",
" [0, Tp_test[0], 0, Tp_test[1]],\n",
" [Tp_test[1], 0, Tp_test[0], 0],\n",
" [0, Tp_test[1], 0, Tp_test[0]],\n",
"])\n",
"Ta_test = np.array([0.8, 0.2])\n",
"TA_test = np.array([\n",
" [Ta_test[0], Ta_test[1], 0, 0],\n",
" [Ta_test[1], Ta_test[0], 0, 0],\n",
" [0, 0, Ta_test[0], Ta_test[1]],\n",
" [0, 0, Ta_test[1], Ta_test[0]],\n",
"])\n",
"TA_test"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c70fed56",
"metadata": {},
"outputs": [],
"source": [
"(TP_test@TA_test)@S_test_iii"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e5339fe5-2b2f-48a6-aa1e-2f30b319cc38",
"id": "7606e236",
"metadata": {},
"outputs": [],
"source": [
"(TP.inv() @ F1.inv() @ F2.inv() @ TA.inv()).simplify()"
" ground_truth = np.array([0, 4, 5, 0])\n",
" analyzer = np.array([[0.8, 0.2], [0.2, 0.8]])\n",
" polarizer = np.array([[0.8, 0.2], [0.2, 0.8]])\n",
" identity = np.array([[1.0, 0.0], [0.0, 1.0]])\n",
" intensity = (\n",
" np.kron(identity, analyzer) @ np.kron(polarizer, identity) @ ground_truth\n",
" )\n",
"intensity\n",
"\n"
]
},
{
Expand All @@ -221,8 +493,8 @@
"for s in (\n",
" '\\hat{T}_P^{-1} = ' + sp.latex(TP.inv().simplify()),\n",
" '\\hat{T}_A^{-1} = ' + sp.latex(TA.inv().simplify()),\n",
" '\\hat{F}_1^{-1} = ' + sp.latex(F1.inv().simplify()),\n",
" '\\hat{F}_2^{-1} = ' + sp.latex(F2.inv().simplify()),\n",
" '\\hat{F}_1^{-1} = ' + sp.latex(F1_parallel.inv().simplify()),\n",
" '\\hat{F}_2^{-1} = ' + sp.latex(F2_parallel.inv().simplify()),\n",
"):\n",
" print(s, end='\\n\\n')"
]
Expand All @@ -244,7 +516,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down

0 comments on commit bb4dc9e

Please sign in to comment.