Skip to content

Commit

Permalink
bare demo of diff() override of sp.diff()
Browse files Browse the repository at this point in the history
  • Loading branch information
gutow committed May 11, 2020
1 parent ac67b31 commit 934ccb6
Showing 1 changed file with 77 additions and 69 deletions.
146 changes: 77 additions & 69 deletions Simple syntax for typeset sympy mathematical operations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,67 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"_Assignment statements_"
"_Demonstratons of `diff()` function_"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"$- \\frac{2 a b}{c^{3}}$"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"$\\frac{\\partial^{}p }{\\partial c^{} }=\\frac{\\partial^{} }{\\partial c^{} }{\\left(\\frac{a b}{c^{2}}\\right)}=- \\frac{2 a b}{c^{3}}$"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"-2*a*b/c**3"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = a*b/c**2\n",
"dmo(sp.diff(p,c))\n",
"diff(p,c)\n",
"sp.diff(p,c)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"_Assignment statements_"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -357,7 +411,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand All @@ -366,7 +420,7 @@
"b*psi/c"
]
},
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -378,7 +432,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand All @@ -401,7 +455,7 @@
"[3, 4]])"
]
},
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -413,7 +467,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -435,7 +489,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand All @@ -457,7 +511,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -492,7 +546,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -514,7 +568,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand All @@ -536,7 +590,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -571,7 +625,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"metadata": {},
"outputs": [
{
Expand All @@ -593,7 +647,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -627,7 +681,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand All @@ -649,7 +703,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand All @@ -671,7 +725,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 22,
"metadata": {},
"outputs": [
{
Expand All @@ -693,7 +747,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 23,
"metadata": {},
"outputs": [
{
Expand All @@ -715,7 +769,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 24,
"metadata": {},
"outputs": [
{
Expand All @@ -724,7 +778,7 @@
"-0.7027 - 0.7115*I"
]
},
"execution_count": 23,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -735,43 +789,9 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"x"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/latex": [
"$$\\int e^{x} \\cos{\\left(x \\right)}\\, dx = \\frac{e^{x} \\sin{\\left(x \\right)}}{2} + \\frac{e^{x} \\cos{\\left(x \\right)}}{2}$$"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/latex": [
"$\\frac{d}{d x} e^{x} \\cos{\\left(x \\right)} = - e^{x} \\sin{\\left(x \\right)} + e^{x} \\cos{\\left(x \\right)}$"
],
"text/plain": [
"<IPython.core.display.Latex object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"#alternative that works for derivatives and integrals using special sympy builtins..\n",
"from IPython.display import display, Latex\n",
Expand All @@ -791,21 +811,9 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "pretty_print() got an unexpected keyword argument 'ppd'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-25-be9acd04610b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0msympy\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mvar\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'ppa ppb ppc'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mpretty_print\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mppd\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mppa\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mppb\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0mppc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: pretty_print() got an unexpected keyword argument 'ppd'"
]
}
],
"outputs": [],
"source": [
"# abuse of pretty_print. It does not handle what dmo does.\n",
"from sympy import *\n",
Expand Down

0 comments on commit 934ccb6

Please sign in to comment.