|
34 | 34 | "source": [ |
35 | 35 | "# Create the function\n", |
36 | 36 | "\n", |
37 | | - "Write the Python function for the above equation" |
| 37 | + "TODO: Write the above equation as a function named \"my_func\"" |
38 | 38 | ] |
39 | 39 | }, |
40 | 40 | { |
|
45 | 45 | }, |
46 | 46 | "outputs": [], |
47 | 47 | "source": [ |
48 | | - "# Do the imports" |
| 48 | + "# Do the imports - you'll need fminbound from scipy.iptimize and quad from scipy.integrate in addition to the usual numpy/matplotlib" |
49 | 49 | ] |
50 | 50 | }, |
51 | 51 | { |
|
67 | 67 | }, |
68 | 68 | "outputs": [], |
69 | 69 | "source": [ |
| 70 | + "# Check my_func is returning the correct answer for a couple x values\n", |
70 | 71 | "print(f\"Func at 1.0 is {my_func(1.0)}, expected -2.433333\")\n", |
71 | 72 | "print(f\"Func at 2.0 is {my_func(2.0)}, expected -4.02694589\")" |
72 | 73 | ] |
|
90 | 91 | "editable": false |
91 | 92 | }, |
92 | 93 | "source": [ |
93 | | - "# Plot the function, along with the bounds and an x at minima and maxima\n", |
| 94 | + "# Minima/maxima and Plot\n", |
94 | 95 | "\n", |
95 | | - "Use 0.5 and 3.0 as the integration bounds" |
| 96 | + "Find the minima/maxima within the bounds **a=0.5** and **b=3.0**\n", |
| 97 | + "\n", |
| 98 | + "Plot the function, along with the minima/maxima\n" |
96 | 99 | ] |
97 | 100 | }, |
98 | 101 | { |
|
103 | 106 | }, |
104 | 107 | "outputs": [], |
105 | 108 | "source": [ |
106 | | - "# Integration limits\n", |
| 109 | + "# Integration limits and the boundaries of the search for minima and maxima\n", |
107 | 110 | "a = 0.5\n", |
108 | 111 | "b = 3.0" |
109 | 112 | ] |
|
116 | 119 | }, |
117 | 120 | "outputs": [], |
118 | 121 | "source": [ |
119 | | - "# Find the x locations of the two bends\n", |
120 | | - "#\n", |
| 122 | + "# TODO Find the x locations of the two bends (minima and maxima)\n", |
| 123 | + "# Use fminbound for both of these\n", |
| 124 | + "# Reminder that the maximum can be found by negating\n", |
| 125 | + "# You might find a lambda function useful\n", |
| 126 | + "# Use the ability to set bounds to keep the search to just the \"bump\" around the minima or maxima (you can hardwire these bounds)\n", |
| 127 | + "# I'd suggest plotting the function and/or looking at the plot in the slides to find reasonable bounds\n", |
121 | 128 | "first_max = ...\n", |
122 | 129 | "first_min = ...\n", |
123 | | - "# END PROMPT \"\"\"\n", |
124 | 130 | "\n", |
125 | 131 | "print(f\"Max {first_max}, expected 0.94813, Min {first_min}, expected 2.091114\")" |
126 | 132 | ] |
|
133 | 139 | }, |
134 | 140 | "outputs": [], |
135 | 141 | "source": [ |
136 | | - "..." |
| 142 | + "# TODO Plot the function from a to b\n", |
| 143 | + "# TODO Put a green x at the first maxima, and a red x at the first minima" |
137 | 144 | ] |
138 | 145 | }, |
139 | 146 | { |
|
169 | 176 | }, |
170 | 177 | "outputs": [], |
171 | 178 | "source": [ |
| 179 | + "# TODO: Numerically calculate the derivative at the minima/maxima\n", |
172 | 180 | "deriv_max = ...\n", |
173 | | - "deriv_min = ...\n", |
174 | | - "# END PROMPT\"\"\"" |
| 181 | + "deriv_min = ..." |
175 | 182 | ] |
176 | 183 | }, |
177 | 184 | { |
|
195 | 202 | "source": [ |
196 | 203 | "# Integration\n", |
197 | 204 | "\n", |
198 | | - "TODO Calculate the area under the curve using trapz or quad, whichever you perfer." |
| 205 | + "TODO Calculate the area under the curve using **trapz** or **quad**, whichever you perfer." |
199 | 206 | ] |
200 | 207 | }, |
201 | 208 | { |
|
206 | 213 | }, |
207 | 214 | "outputs": [], |
208 | 215 | "source": [ |
209 | | - "...\n", |
210 | 216 | "\n", |
211 | | - "area_under_curve = ...\n", |
212 | | - "# END PROMPT\"\"\"" |
| 217 | + "area_under_curve = ..." |
213 | 218 | ] |
214 | 219 | }, |
215 | 220 | { |
|
319 | 324 | "name": "python", |
320 | 325 | "nbconvert_exporter": "python", |
321 | 326 | "pygments_lexer": "ipython3", |
322 | | - "version": "3.11.4" |
| 327 | + "version": "3.11.0" |
323 | 328 | }, |
324 | 329 | "otter": { |
325 | 330 | "OK_FORMAT": true, |
|
0 commit comments