Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions other_python_stuff/year2/sympy/sympy.ipynb → book/08/sympy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,37 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy; Aside from obvious simplifications like $x - x = 0$ and $\\sqrt{8} = 2\\sqrt{2}$, most simplifications are not performed automatically. "
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy, however; consider this example:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAAVCAYAAADCUymGAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAD3klEQVRYCd2Y0VEbMRCGL4wL8FCC6YCECmJ3QEgFCR04kyf8xjgdABVkQgeQCojpwO4gHndA/k8naWRZd8Hn9RCyM3uSVtKvvdXuSnfV09NTZc0XFxcDa8zXgFd674PKmCaTyViQx8awrwVu4N8/6vsGz7AigZ8K60TlFyvMfeJIz4Hwg67vVF/Slvyx67qai4OtVF6DYWZgAfaF91PlW4D/dZKeGPdK5SjoqvpUdQw0Uv0+yLctNXemOe9VrixTBMpdbavMLuP1AkPx544Y6HuezhUW3rwS/0jlHerYAfzK0sBnUtCFRQeFuk4hauAuNNSkuXTO5+O5fcnx8E7k7YA9+iYGFhC5d9FJm5ebhCEX0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},
"output_type": "display_data"
}
],
"source": [
"x*expr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A general formula to simplify formulas is `sym.simplify`, which attempts to apply all of these functions in an intelligent way to arrive at the simplest form of an expression:"
"Aside from obvious simplifications like $x - x = 0$ and $\\sqrt{8} = 2\\sqrt{2}$, most simplifications are not performed automatically. A general formula to simplify formulas is `sym.simplify`, which attempts to apply all of these functions in an intelligent way to arrive at the simplest form of an expression:"
]
},
{
Expand Down Expand Up @@ -1139,7 +1162,7 @@
"source": [
":::{card} Test yourself!\n",
"\n",
"Create a symbolic expression representing [Newton's Law of Universal Gravitation](https://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation). Use `sym.lambdify()` to evaluate the expression for two mass of 5.972E24 kg and 80 kg at a distance of 6371 km apart to find the gravitational force in Newtons. $G$ equals $6.67430\\cdot 10 ^{11}$\n",
"Create a symbolic expression representing [Newton's Law of Universal Gravitation](https://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation). Use `sym.lambdify()` to evaluate the expression for two mass of 5.972E24 kg and 80 kg at a distance of 6371 km apart to find the gravitational force in Newtons. $G$ equals $6.67430\\cdot 10 ^{-11}$\n",
"\n",
"All variables have been defined with:\n",
"```python\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy, however:"
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy, however; consider this example:"
]
},
{
Expand Down Expand Up @@ -344,14 +344,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice something in the above example. When we typed `expr - x`, we did not get $x + 2y - x$, but rather just $2y$. The $x$ and the $-x$ automatically canceled one another. This is similar to how $\\sqrt{8}$ automatically turned into $2\\sqrt{2}$ above. This isn’t always the case in SymPy; Aside from obvious simplifications like $x - x = 0$ and $\\sqrt{8} = 2\\sqrt{2}$, most simplifications are not performed automatically. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A general formula to simplify formulas is `sym.simplify`, which attempts to apply all of these functions in an intelligent way to arrive at the simplest form of an expression:"
"Aside from obvious simplifications like $x - x = 0$ and $\\sqrt{8} = 2\\sqrt{2}$, most simplifications are not performed automatically. A general formula to simplify formulas is `sym.simplify`, which attempts to apply all of these functions in an intelligent way to arrive at the simplest form of an expression:"
]
},
{
Expand Down Expand Up @@ -516,7 +509,13 @@
"\n",
"Create an expression for the normal distribution function:\n",
"\n",
"$$\\frac{1}{\\sqrt{2\\pi\\sigma}}e^{\\frac{(x-\\mu)^2}{2\\sigma^2}}$$"
"$$\\frac{1}{\\sqrt{2\\pi\\sigma}}e^{\\frac{(x-\\mu)^2}{2\\sigma^2}}$$\n",
"\n",
"First define variables with:\n",
"\n",
"```python\n",
"sym.var('x, sigma, mu')\n",
"```"
]
},
{
Expand All @@ -525,6 +524,7 @@
"metadata": {},
"outputs": [],
"source": [
"# define variables\n",
"expr = \n",
"expr #displays expression"
]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 9 additions & 7 deletions book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ parts:
sections:
- file: 07/Exercises/01.ipynb
- file: 07/Exercises/bug_report.md
- file: 08/intro.md
title: 8. Errors
- file: 08/sympy
title: 8. SymPy
- file: 09/intro.md
title: 9. Errors
sections:
- file: 08/error_types.ipynb
- file: 08/traceback.ipynb
- file: 08/raise_errors.ipynb
- file: 08/handling_errors.ipynb
- file: 08/asserts.ipynb
- file: 09/error_types.ipynb
- file: 09/traceback.ipynb
- file: 09/raise_errors.ipynb
- file: 09/handling_errors.ipynb
- file: 09/asserts.ipynb
- caption: End of course survey
chapters:
- file: End-of-course-survey.md
Expand Down
17 changes: 14 additions & 3 deletions book/references.bib
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
---
---

@inproceedings{holdgraf_evidence_2014,
address = {Brisbane, Australia, Australia},
title = {Evidence for {Predictive} {Coding} in {Human} {Auditory} {Cortex}},
Expand Down Expand Up @@ -54,3 +51,17 @@ @book{ruby
year = {2008},
publisher = {O'Reilly Media}
}

@misc{sympy_why,
title={Sympy documentation},
author={{SymPy Development Team}},
howpublished={\url{https://docs.sympy.org/latest/tutorials/intro-tutorial/intro.html}},
year={2023}
}

@misc{jason_moore,
title={Learn Multibody Dynamics, SymPy},
author={Moore, Jason},
howpublished={\url{https://moorepants.github.io/learn-multibody-dynamics/sympy.html}},
year={2023}
}