Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 16321c2

Browse files
Update sympy page based on week 1.8 stuff (#11)
* added sympy * Update references.bib * Update _toc.yml * renamed folder * Update references.bib * Update sympy.ipynb * 2 edits --------- Co-authored-by: Tom van Woudenberg <t.r.vanwoudenberg@tudelft.nl>
1 parent c74f09a commit 16321c2

10 files changed

Lines changed: 59 additions & 23 deletions

other_python_stuff/year2/sympy/sympy.ipynb renamed to book/08/sympy.ipynb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,37 @@
409409
"cell_type": "markdown",
410410
"metadata": {},
411411
"source": [
412-
"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. "
412+
"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:"
413+
]
414+
},
415+
{
416+
"cell_type": "code",
417+
"execution_count": null,
418+
"metadata": {},
419+
"outputs": [
420+
{
421+
"data": {
422+
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAFgAAAAVCAYAAADCUymGAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAD3klEQVRYCd2Y0VEbMRCGL4wL8FCC6YCECmJ3QEgFCR04kyf8xjgdABVkQgeQCojpwO4gHndA/k8naWRZd8Hn9RCyM3uSVtKvvdXuSnfV09NTZc0XFxcDa8zXgFd674PKmCaTyViQx8awrwVu4N8/6vsGz7AigZ8K60TlFyvMfeJIz4Hwg67vVF/Slvyx67qai4OtVF6DYWZgAfaF91PlW4D/dZKeGPdK5SjoqvpUdQw0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fgdPVaancOj+r0u/CXxqxyvdHwOidMKb8DIVAAAAAElFTkSuQmCC",
423+
"text/latex": [
424+
"$\\displaystyle x \\left(x + 2 y\\right)$"
425+
],
426+
"text/plain": [
427+
"x⋅(x + 2⋅y)"
428+
]
429+
},
430+
"metadata": {},
431+
"output_type": "display_data"
432+
}
433+
],
434+
"source": [
435+
"x*expr"
413436
]
414437
},
415438
{
416439
"cell_type": "markdown",
417440
"metadata": {},
418441
"source": [
419-
"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:"
442+
"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:"
420443
]
421444
},
422445
{
@@ -1139,7 +1162,7 @@
11391162
"source": [
11401163
":::{card} Test yourself!\n",
11411164
"\n",
1142-
"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",
1165+
"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",
11431166
"\n",
11441167
"All variables have been defined with:\n",
11451168
"```python\n",

other_python_stuff/year2/sympy/sympy_stripped.ipynb renamed to book/08/sympy_stripped.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
"cell_type": "markdown",
314314
"metadata": {},
315315
"source": [
316-
"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:"
316+
"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:"
317317
]
318318
},
319319
{
@@ -344,14 +344,7 @@
344344
"cell_type": "markdown",
345345
"metadata": {},
346346
"source": [
347-
"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. "
348-
]
349-
},
350-
{
351-
"cell_type": "markdown",
352-
"metadata": {},
353-
"source": [
354-
"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:"
347+
"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:"
355348
]
356349
},
357350
{
@@ -516,7 +509,13 @@
516509
"\n",
517510
"Create an expression for the normal distribution function:\n",
518511
"\n",
519-
"$$\\frac{1}{\\sqrt{2\\pi\\sigma}}e^{\\frac{(x-\\mu)^2}{2\\sigma^2}}$$"
512+
"$$\\frac{1}{\\sqrt{2\\pi\\sigma}}e^{\\frac{(x-\\mu)^2}{2\\sigma^2}}$$\n",
513+
"\n",
514+
"First define variables with:\n",
515+
"\n",
516+
"```python\n",
517+
"sym.var('x, sigma, mu')\n",
518+
"```"
520519
]
521520
},
522521
{
@@ -525,6 +524,7 @@
525524
"metadata": {},
526525
"outputs": [],
527526
"source": [
527+
"# define variables\n",
528528
"expr = \n",
529529
"expr #displays expression"
530530
]
File renamed without changes.

book/_toc.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ parts:
4242
sections:
4343
- file: 07/Exercises/01.ipynb
4444
- file: 07/Exercises/bug_report.md
45-
- file: 08/intro.md
46-
title: 8. Errors
45+
- file: 08/sympy
46+
title: 8. SymPy
47+
- file: 09/intro.md
48+
title: 9. Errors
4749
sections:
48-
- file: 08/error_types.ipynb
49-
- file: 08/traceback.ipynb
50-
- file: 08/raise_errors.ipynb
51-
- file: 08/handling_errors.ipynb
52-
- file: 08/asserts.ipynb
50+
- file: 09/error_types.ipynb
51+
- file: 09/traceback.ipynb
52+
- file: 09/raise_errors.ipynb
53+
- file: 09/handling_errors.ipynb
54+
- file: 09/asserts.ipynb
5355
- caption: End of course survey
5456
chapters:
5557
- file: End-of-course-survey.md

book/references.bib

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
---
2-
---
3-
41
@inproceedings{holdgraf_evidence_2014,
52
address = {Brisbane, Australia, Australia},
63
title = {Evidence for {Predictive} {Coding} in {Human} {Auditory} {Cortex}},
@@ -54,3 +51,17 @@ @book{ruby
5451
year = {2008},
5552
publisher = {O'Reilly Media}
5653
}
54+
55+
@misc{sympy_why,
56+
title={Sympy documentation},
57+
author={{SymPy Development Team}},
58+
howpublished={\url{https://docs.sympy.org/latest/tutorials/intro-tutorial/intro.html}},
59+
year={2023}
60+
}
61+
62+
@misc{jason_moore,
63+
title={Learn Multibody Dynamics, SymPy},
64+
author={Moore, Jason},
65+
howpublished={\url{https://moorepants.github.io/learn-multibody-dynamics/sympy.html}},
66+
year={2023}
67+
}

0 commit comments

Comments
 (0)