Skip to content

Instantly share code, notes, and snippets.

@goerz
Last active February 19, 2020 18:08
Show Gist options
  • Save goerz/51b42cec6c420041e91a2b19e0f414b9 to your computer and use it in GitHub Desktop.
Save goerz/51b42cec6c420041e91a2b19e0f414b9 to your computer and use it in GitHub Desktop.
Schirmer Extension
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:56.001789Z",
"start_time": "2020-02-19T18:06:55.247441Z"
}
},
"outputs": [],
"source": [
"import sympy\n",
"from sympy import Matrix, symbols, I"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:56.008682Z",
"start_time": "2020-02-19T18:06:56.004350Z"
}
},
"outputs": [],
"source": [
"H, μ1, μ2, dt, Ψ = symbols('H, μ_1, μ_2, dt, Psi')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:56.406472Z",
"start_time": "2020-02-19T18:06:56.011071Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}- i H dt & 0\\\\- i dt μ_{1} & - i H dt\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ -I*H*dt, 0],\n",
"[-I*dt*μ_1, -I*H*dt]])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"schirmer = -I * Matrix([[H, 0], [μ1, H]]) * dt;\n",
"schirmer"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:56.415870Z",
"start_time": "2020-02-19T18:06:56.409485Z"
}
},
"outputs": [],
"source": [
"state = Matrix([[Ψ], [0]])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:56.510462Z",
"start_time": "2020-02-19T18:06:56.419747Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}e^{- i H dt} & 0\\\\- i dt μ_{1} e^{- i H dt} & e^{- i H dt}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ exp(-I*H*dt), 0],\n",
"[-I*dt*μ_1*exp(-I*H*dt), exp(-I*H*dt)]])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sympy.exp(schirmer)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:56.584020Z",
"start_time": "2020-02-19T18:06:56.513212Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\Psi e^{- i H dt}\\\\- i \\Psi dt μ_{1} e^{- i H dt}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ Psi*exp(-I*H*dt)],\n",
"[-I*Psi*dt*μ_1*exp(-I*H*dt)]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sympy.exp(schirmer) * state"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:56.602408Z",
"start_time": "2020-02-19T18:06:56.586884Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}- i H dt & 0 & 0\\\\- i dt μ_{1} & - i H dt & 0\\\\- i dt μ_{2} & 0 & - i H dt\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ -I*H*dt, 0, 0],\n",
"[-I*dt*μ_1, -I*H*dt, 0],\n",
"[-I*dt*μ_2, 0, -I*H*dt]])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"schirmer2 = -I * Matrix([[H, 0, 0], [μ1, H, 0], [μ2, 0, H]]) * dt;\n",
"schirmer2"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:56.616580Z",
"start_time": "2020-02-19T18:06:56.604972Z"
}
},
"outputs": [],
"source": [
"state2 = Matrix([[Ψ], [0], [0]])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:56.831036Z",
"start_time": "2020-02-19T18:06:56.622499Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}e^{- i H dt} & 0 & 0\\\\- i dt μ_{1} e^{- i H dt} & e^{- i H dt} & 0\\\\- i dt μ_{2} e^{- i H dt} & 0 & e^{- i H dt}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ exp(-I*H*dt), 0, 0],\n",
"[-I*dt*μ_1*exp(-I*H*dt), exp(-I*H*dt), 0],\n",
"[-I*dt*μ_2*exp(-I*H*dt), 0, exp(-I*H*dt)]])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sympy.exp(schirmer2)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2020-02-19T18:06:57.018227Z",
"start_time": "2020-02-19T18:06:56.835218Z"
}
},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle \\left[\\begin{matrix}\\Psi e^{- i H dt}\\\\- i \\Psi dt μ_{1} e^{- i H dt}\\\\- i \\Psi dt μ_{2} e^{- i H dt}\\end{matrix}\\right]$"
],
"text/plain": [
"Matrix([\n",
"[ Psi*exp(-I*H*dt)],\n",
"[-I*Psi*dt*μ_1*exp(-I*H*dt)],\n",
"[-I*Psi*dt*μ_2*exp(-I*H*dt)]])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sympy.exp(schirmer2) * state2"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment