Skip to content

Instantly share code, notes, and snippets.

@Jason-S-Ross
Last active September 8, 2021 16:07
Show Gist options
  • Save Jason-S-Ross/4eeb7a07087d8e833dfd8de6c79cf0c1 to your computer and use it in GitHub Desktop.
Save Jason-S-Ross/4eeb7a07087d8e833dfd8de6c79cf0c1 to your computer and use it in GitHub Desktop.
Conformal Mapping Demo
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from numpy import sin, cos, tan, arcsin, arccos, arctan\n",
"from numpy import sinh, cosh, tanh, arcsinh, arccosh, arctanh\n",
"from numpy import log\n",
"from bqplot import Figure, Scale, Scatter, Axis, LinearScale, Lines\n",
"import ipywidgets as widgets\n",
"from sympy import latex, sympify"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"x = np.arange(-5, 5, 0.2)\n",
"y = np.arange(-5, 5, 0.2)\n",
"xx, yy = np.meshgrid(x, y)\n",
"\n",
"Min_Input = 0\n",
"Max_Input = 5\n",
"Num_Segments = 200\n",
"Num_Gridlines = 10\n",
"sc_x = LinearScale(min=-5, max=5)\n",
"sc_y = LinearScale(min=-5, max=5)\n",
"LineBasis = np.linspace(Min_Input, Max_Input, num=Num_Segments+1) + 0.00001\n",
"GridBasis = np.linspace(Min_Input, Max_Input, num=Num_Gridlines) + 0.00001\n",
"HLineX, HLineY = np.meshgrid(LineBasis, GridBasis)\n",
"GridLineX = np.vstack([HLineX, HLineY])\n",
"GridLineY = np.vstack([HLineY, HLineX])\n",
"GridLineX = np.vstack([HLineX, HLineX, -HLineX, -HLineX, HLineY, -HLineY, HLineY, -HLineY])\n",
"GridLineY = np.vstack([HLineY, -HLineY, HLineY, -HLineY, HLineX, HLineX, -HLineX, -HLineX])\n",
"GridLines = Lines(x=GridLineX, y=GridLineY, colors = ['black'], scales={'x': sc_x, 'y': sc_y})\n",
"ZGrid = GridLineX + 1j*GridLineY\n",
"Z = ZGrid\n",
"ZLines = Lines(x=Z.real, y=Z.imag, colors = ['blue'], scales={'x': sc_x, 'y': sc_y})\n",
"Fig = Figure(marks=[GridLines, ZLines])\n",
"Fig.layout.width='800px'\n",
"Fig.layout.height='800px'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"Controller = widgets.FloatSlider(value=1, min=0, max=4, step=0.01)\n",
"FuncBox = widgets.Text()\n",
"FuncRepBox = widgets.Label()\n",
"\n",
"def UpdateFunc(change):\n",
" FuncBox.Func = eval('lambda Z, a: {}'.format(change['new']))\n",
" ZTrans=FuncBox.Func(ZGrid, Controller.value)\n",
" ZLines.x = ZTrans.real\n",
" ZLines.y = ZTrans.imag\n",
" FuncRepBox.value = '${}$'.format(latex(sympify(change['new'])))\n",
"\n",
" \n",
"def UpdateParam(change):\n",
" ZTrans=FuncBox.Func(ZGrid, change['new'])\n",
" ZLines.x = ZTrans.real\n",
" ZLines.y = ZTrans.imag\n",
" \n",
" \n",
"Controller.observe(UpdateParam, names='value')\n",
"FuncBox.observe(UpdateFunc, names='value')\n",
"FuncBox.value='1/(1+Z**a)**(1/a)'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9b8aaa8472f340b7a30f23523d974c68",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Text(value='1/(1+Z**a)**(1/a)'), Label(value='$\\\\left(Z^{a} + 1\\\\right)^{- \\\\frac{1}{a}}$'), Fl…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"widgets.VBox([FuncBox,FuncRepBox,Controller, Fig])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment