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

Commit 66c144a

Browse files
committed
sympy-revision
1 parent 0e2eaa7 commit 66c144a

File tree

3 files changed

+214
-619
lines changed

3 files changed

+214
-619
lines changed

book/_toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ parts:
113113
- file: sympy/introduction.ipynb
114114
title: "Introduction"
115115
- file: sympy/variables.ipynb
116-
title: "Variables, Expressions and Functions"
116+
title: "Variables"
117+
- file: sympy/functions.ipynb
118+
title: "Functions"
117119
- file: sympy/expressions.ipynb
118120
title: "Evaluating Expressions"
119121

book/sympy/functions.ipynb

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Functions"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"You will also work with undefined mathematical functions in addition to variables.\n",
15+
"These will play an important role in setting up differential equations, where\n",
16+
"you typically don't know the function, but only its derivative(s). You can\n",
17+
"create arbitrary functions of variables. In this case, you make a function of\n",
18+
"$x$. First create the function name:"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 17,
24+
"metadata": {
25+
"tags": [
26+
"disable-execution-cell"
27+
]
28+
},
29+
"outputs": [],
30+
"source": [
31+
"f = sym.Function('f')"
32+
]
33+
},
34+
{
35+
"cell_type": "markdown",
36+
"metadata": {},
37+
"source": [
38+
"Now you can create functions of one or more variables like so:"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": 18,
44+
"metadata": {
45+
"tags": [
46+
"disable-execution-cell"
47+
]
48+
},
49+
"outputs": [
50+
{
51+
"data": {
52+
"image/png": "iVBORw0KGgoAAAANSUhEUgAAACUAAAAVCAYAAADB5CeuAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACf0lEQVRIDa2W7VHbQBCGFSYFmHQQlUBCB9ABIRUk7sCZ/LL/MdCBoQKGdEA6gNABLsFxB87zHCflJOuEBnlnVvf17qu93b2Tiu12W4zV+XxevpWjy/agGCmLxWIGxdEImjJy1BTv3GFOAC9Z28T1C8ZVP0wxPqNzTPsjYt7UYO/GNrTXEmQjBeCS9Q/oLfodPUFrYX3C4CftKIckhOOKZho5804B0hEd0rFH9Deaik4byX2JXHIWnenDY6Nyjx7Sb6RMI4X5v+jhy2g/Tzlh+phL3ymLK0A5h6yl1X5cabDIef4+ncIJU6ZDRmrN+C62U9pUxLTTWa9jZ73JpRyj39AS/YoqD2B+vXQbTzlPG5ECeI1+YUHSpX207ZAsn9FnOxm5xO5KZf0BvUFPGHso5A61Q9sWOctGpERg6I6UbCRYk3gtqC3YG6H0pRvGpttoKR6cdD1Mxoecu04xGS5CyJ9SdKsvsS/rkkds03r7BOiJuYCnNRM50W7SSF9EWgMpaY6gc75jM+cAbzvBu5Nhs11OGam+KEllmE1hr+CgB0ZcXdTMTdSMofPrnZpi0iK+yBhV00ayqr1qrogv88Ra6Nakh8TPRxr5vq+AkVo1IoWxL9Lb1yLlumlui5FRvU7CrlMAc655GnMS6q8dKVNXYNx38oRYI0akLdr5UfXl8vg9u0f9hPxBdbZOpZiWaDdt/Evxb7NE74b8G4F7Ro+GYIdg4CrlFHuA52dotWvraehJ8a7pulhbmx889GKVM/wl2KlPxCvh1SYIONPkD9pOwUfI4CZyyBX+p6yp4FRs+y62rpeIN8p+C8eINfc/6kPy3YeJtTDrw/StYT+TI8X8A8ObApWBYhW/AAAAAElFTkSuQmCC",
53+
"text/latex": [
54+
"$\\displaystyle f{\\left(x \\right)}$"
55+
],
56+
"text/plain": [
57+
"f(x)"
58+
]
59+
},
60+
"execution_count": 18,
61+
"metadata": {},
62+
"output_type": "execute_result"
63+
}
64+
],
65+
"source": [
66+
"f(x)"
67+
]
68+
},
69+
{
70+
"cell_type": "markdown",
71+
"metadata": {},
72+
"source": [
73+
"The same `UndefinedFunction` can be used to create multivariate functions:"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": 19,
79+
"metadata": {
80+
"tags": [
81+
"disable-execution-cell"
82+
]
83+
},
84+
"outputs": [
85+
{
86+
"data": {
87+
"image/png": "iVBORw0KGgoAAAANSUhEUgAAADkAAAAVCAYAAAD8dkbIAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADW0lEQVRYCc2X7VEbMRCGHYYCDB3E6YCEDqADh1QAdOBMftn/GNOBQwUM6YB0wEcH0EGIOyDPI+suurNk7NiZ8c7sSVrt7r2rXel0ndfX1866PBwOe+v62JR9DstOZ00ajUYDXBys6WaT5r2Iqfb5zhUsEcoT5qZx/oJx1Q8ixn06h7Rfo85WNOBx4ae03wVUzCQKY+b34Wv4DD6Ca2K+y+Ab7VYFKEAwXdKcR4zlIFEyMAM00Hv4J5ySi2Cmt5XEJsZOtlxZAbN2C+/Rb5SoRhLy3/DebLSdTzGC7H2pXI+ZfEapFKB78Xk7Q2ugEuPJbioiKEvUAM3kC+Ob2J7TpqROu3zreezcr/qSDuFTuAd/gaU7dH7Muss9E58fsHhgHA4VrePcFe3nljcxHjcyqWFUFOTEPtwOUD+f4Cc7BRpjdykzfwdfwUeMPaT0HfYK7SrkIac/t1Hb/gSZ1dUmMfYamVQDR664VMwUcwJ9UalN2JvBFMSUsQDMpuRBls4H4aIHPv0Ou1iSVdR+d6my1JsPEqEODfbRtkACFXyO7rFN9+tHlB6RBX3adknlfLRlng8VHrN20VJwe7Vlqoij2yhXpZB7KAUZhMs+EjCViaCuq8G/tMkCGYxVlO5Hk6IsV3khGbkgNapWjW6WLAMdLyTAVaDqQwZZV15oWJ60CuqqiGq+w9tNDrPveckF6aFS1X/0M9eY6Wrv1pMxgFtaXyx5aAkgrQwPkGmYjQ/t0vGCvu9Mfala2o/OmcnnRpC8TCe+MLcqiGty3rJuk8HJfn7CKqYKyJxrLGDU82LxkOoW+o0Aoz99euLmKJwHjSDRslQ7GOfqO3XiHgu6qZC+du4XX3yGHzN5SuvnyFPXUq1Ll3GHsVkV/DJlHO7J2PiJ8hJeHWIlvLMFSP/j+BebwDeprNRH7wk+KM2vKsdXH+6uYof+GH7I2SDvwU/O7bAiffiGVZHcj8uehH7rzNSmyF82s5ol5sxeXdL03Q5WR+7ToQ+zLsbwF2KnLhWMG+WkUo7Qsyz9QXUfr0UR8K83nHihSBPgLcob2hzeiEls4VOzi2IIMrZVjTNcitS3Cjzh1iH3r1e2RWRm9tFzL3p/dZ+X9qK/WX+rLFfPq8hi7Q9WsfmfuuAZiCl9xx8E4gWsmkncfAAAAABJRU5ErkJggg==",
88+
"text/latex": [
89+
"$\\displaystyle f{\\left(x,y \\right)}$"
90+
],
91+
"text/plain": [
92+
"f(x, y)"
93+
]
94+
},
95+
"execution_count": 19,
96+
"metadata": {},
97+
"output_type": "execute_result"
98+
}
99+
],
100+
"source": [
101+
"f(x,y)"
102+
]
103+
},
104+
{
105+
"cell_type": "markdown",
106+
"metadata": {},
107+
"source": [
108+
":::{card} Test yourself!\n",
109+
"Create a function $H(x,y,z)$\n",
110+
"\n",
111+
"All variables have been defined with:\n",
112+
"\n",
113+
"```python\n",
114+
"x, y, z = sym.symbols('x, y, z')\n",
115+
"```\n",
116+
"\n",
117+
"Click {fa}`rocket` --> {guilabel}`Live Code` to activate live coding!\n",
118+
":::"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": 20,
124+
"metadata": {
125+
"tags": [
126+
"thebe-remove-input-init"
127+
]
128+
},
129+
"outputs": [],
130+
"source": [
131+
"x, y, z = sym.symbols('x, y, z')\n",
132+
"H = sym.Function('H')\n",
133+
"function_correct = H(x,y,z)\n",
134+
"function_answer = 0\n",
135+
"H = None"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": null,
141+
"metadata": {},
142+
"outputs": [],
143+
"source": [
144+
"function = "
145+
]
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": 22,
150+
"metadata": {
151+
"tags": [
152+
"thebe-remove-input-init"
153+
]
154+
},
155+
"outputs": [
156+
{
157+
"data": {
158+
"application/vnd.jupyter.widget-view+json": {
159+
"model_id": "bf9cdc4356624837a034f353336aeb2a",
160+
"version_major": 2,
161+
"version_minor": 0
162+
},
163+
"text/plain": [
164+
"Button(description='Check answer', style=ButtonStyle())"
165+
]
166+
},
167+
"metadata": {},
168+
"output_type": "display_data"
169+
},
170+
{
171+
"data": {
172+
"application/vnd.jupyter.widget-view+json": {
173+
"model_id": "8052642635a74e9b966db4bbc3ee54ac",
174+
"version_major": 2,
175+
"version_minor": 0
176+
},
177+
"text/plain": [
178+
"Output()"
179+
]
180+
},
181+
"metadata": {},
182+
"output_type": "display_data"
183+
}
184+
],
185+
"source": [
186+
"check_answer(\"function\",function_correct, check_equation)"
187+
]
188+
}
189+
],
190+
"metadata": {
191+
"kernelspec": {
192+
"display_name": "mude",
193+
"language": "python",
194+
"name": "python3"
195+
},
196+
"language_info": {
197+
"codemirror_mode": {
198+
"name": "ipython",
199+
"version": 3
200+
},
201+
"file_extension": ".py",
202+
"mimetype": "text/x-python",
203+
"name": "python",
204+
"nbconvert_exporter": "python",
205+
"pygments_lexer": "ipython3",
206+
"version": "3.11.4"
207+
}
208+
},
209+
"nbformat": 4,
210+
"nbformat_minor": 2
211+
}

0 commit comments

Comments
 (0)