|
31 | 31 | }, |
32 | 32 | { |
33 | 33 | "cell_type": "code", |
34 | | - "execution_count": 1, |
| 34 | + "execution_count": 2, |
35 | 35 | "metadata": { |
36 | 36 | "tags": [ |
37 | 37 | "hide-input" |
|
161 | 161 | "ax.grid('True',ls=':')" |
162 | 162 | ] |
163 | 163 | }, |
| 164 | + { |
| 165 | + "cell_type": "markdown", |
| 166 | + "metadata": {}, |
| 167 | + "source": [ |
| 168 | + "### Exercises \n", |
| 169 | + "\n", |
| 170 | + "**Exercise 1:** The sales of a company (in million dollars) has been shown in the table below:\n", |
| 171 | + "\n", |
| 172 | + "\n", |
| 173 | + "|Year|Sales|\n", |
| 174 | + "|----|------|\n", |
| 175 | + "|2004|13 |\n", |
| 176 | + "|2006|29|\n", |
| 177 | + "|2008|35|\n", |
| 178 | + "|2010|45|\n", |
| 179 | + "|2012|48|\n", |
| 180 | + "\n", |
| 181 | + "\n", |
| 182 | + "$(a)$ Find the least squares regression line. Plot the regression line and the data points to show that the line fits the data reasonably well.\n", |
| 183 | + "\n", |
| 184 | + "$(b)$ Use the regression line model to estimate the sales of the company in 2020.\n", |
| 185 | + "\n" |
| 186 | + ] |
| 187 | + }, |
| 188 | + { |
| 189 | + "cell_type": "markdown", |
| 190 | + "metadata": {}, |
| 191 | + "source": [ |
| 192 | + "**Exercise 2:** The concept of least squares can also be used to find polynomials of best fit that are of degree greater than one. Given the points $(-1,0),(0,1),(1,3),$ and $(2,9)$, find the parabola $y = ax^2 + bx + c$ that best fits through the points in the sense of least squares. Then plot the points on top of a graph of the parabola to observe the fit. " |
| 193 | + ] |
| 194 | + }, |
| 195 | + { |
| 196 | + "cell_type": "code", |
| 197 | + "execution_count": null, |
| 198 | + "metadata": {}, |
| 199 | + "outputs": [], |
| 200 | + "source": [ |
| 201 | + "## Code solution here." |
| 202 | + ] |
| 203 | + }, |
| 204 | + { |
| 205 | + "cell_type": "markdown", |
| 206 | + "metadata": {}, |
| 207 | + "source": [ |
| 208 | + "**Exercise 3:** Lets revisit a problem we saw earlier to see how the technique of least squares compares to our previous method of interpolation. Here are the average radii of the orbits of the planets in our solar system, and their average orbital velocity around the Sun.\n", |
| 209 | + "\n", |
| 210 | + "|Planet | Distance from Sun (million km) | Orbital Velocity (km/s) |\n", |
| 211 | + "| ------------------------------- | ------------------------------- | ------------------------------- |\n", |
| 212 | + "|Mercury | 57.9 | 47.4 |\n", |
| 213 | + "|Venus | 108.2 | 35.0 | \n", |
| 214 | + "|Earth | 149.6 | 29.8 |\n", |
| 215 | + "|Mars | 228.0 | 24.1 |\n", |
| 216 | + "|Jupiter | 778.5 | 13.1 |\n", |
| 217 | + "|Saturn | 1432.0 | 9.7 |\n", |
| 218 | + "|Uranus | 2867.0 | 6.8 |\n", |
| 219 | + "|Neptune | 4515.0 | 5.4 |\n", |
| 220 | + "\n", |
| 221 | + "$(a)$ Use the method of least squares to find the cubic polynomial of best fit for these points. Plot the data points together with the graph of the polynomial to observe the fit.\n", |
| 222 | + "\n", |
| 223 | + "$(b)$ The dwarf planet Ceres has an average distance from the sun of 413.5 million km. What does the polynomial suggest the value would be? How closely does this agree with what the points seem to suggest?" |
| 224 | + ] |
| 225 | + }, |
| 226 | + { |
| 227 | + "cell_type": "code", |
| 228 | + "execution_count": null, |
| 229 | + "metadata": {}, |
| 230 | + "outputs": [], |
| 231 | + "source": [ |
| 232 | + "## Code solution here." |
| 233 | + ] |
| 234 | + }, |
164 | 235 | { |
165 | 236 | "cell_type": "markdown", |
166 | 237 | "metadata": {}, |
|
213 | 284 | }, |
214 | 285 | { |
215 | 286 | "cell_type": "code", |
216 | | - "execution_count": 5, |
| 287 | + "execution_count": 3, |
217 | 288 | "metadata": {}, |
218 | 289 | "outputs": [ |
219 | 290 | { |
|
225 | 296 | " [0. 0. 0.5774 0. 0. 0. 0. 0.5774 0. 0.5774]\n", |
226 | 297 | " [0. 0. 0.5774 0. 0. 0.5774 0. 0.5774 0. 0. ]\n", |
227 | 298 | " [0. 0.5774 0. 0. 0. 0. 0. 0. 0.5774 0.5774]\n", |
228 | | - " [0. 0. 0.7071 0. 0. 0. 0. 0.7071 0. 0. ]]\n" |
| 299 | + " [0. 0. 0.5774 0. 0.5774 0. 0. 0.5774 0. 0. ]]\n" |
229 | 300 | ] |
230 | 301 | } |
231 | 302 | ], |
|
235 | 306 | "T3 = np.array([[0, 0, 1, 0, 0, 0, 0, 1, 0, 1]])\n", |
236 | 307 | "T4 = np.array([[0, 0, 1, 0, 0, 1, 0, 1, 0, 0]])\n", |
237 | 308 | "T5 = np.array([[0, 1, 0, 0, 0, 0, 0, 0, 1, 1]])\n", |
238 | | - "T6 = np.array([[0, 0, 1, 0, 0, 0, 0, 1, 0, 0]])\n", |
| 309 | + "T6 = np.array([[0, 0, 1, 0, 1, 0, 0, 1, 0, 0]])\n", |
239 | 310 | "\n", |
240 | 311 | "D = np.vstack((T1,T2,T3,T4,T5,T6))\n", |
241 | 312 | "D_scaled = lag.ScaleMatrixRows(D)\n", |
|
263 | 334 | }, |
264 | 335 | { |
265 | 336 | "cell_type": "code", |
266 | | - "execution_count": 6, |
| 337 | + "execution_count": 4, |
267 | 338 | "metadata": {}, |
268 | 339 | "outputs": [ |
269 | 340 | { |
|
275 | 346 | " [0.6667]\n", |
276 | 347 | " [1. ]\n", |
277 | 348 | " [0. ]\n", |
278 | | - " [0.8165]]\n" |
| 349 | + " [0.6667]]\n" |
279 | 350 | ] |
280 | 351 | } |
281 | 352 | ], |
|
333 | 404 | "cell_type": "markdown", |
334 | 405 | "metadata": {}, |
335 | 406 | "source": [ |
336 | | - "**Exercise 3:** The concept of least squares can also be used to find polynomials of best fit that are of degree greater than one. Given the points $(-1,0),(0,1),(1,3),$ and $(2,9)$, find the parabola $y = ax^2 + bx + c$ that best fits through the points in the sense of least squares. Then plot the points ontop of a graph of the parabola to observe the fit. " |
| 407 | + "**Exercise 3:** Suppose that we want to search for entries matching the words \"information\", \"retrieval\", and \"computations\". Use the information discussed in this section to determine the webpage in the database which contains all or most of the keywords in the search vector." |
337 | 408 | ] |
338 | 409 | }, |
339 | 410 | { |
340 | 411 | "cell_type": "code", |
341 | | - "execution_count": null, |
| 412 | + "execution_count": 17, |
342 | 413 | "metadata": {}, |
343 | 414 | "outputs": [], |
344 | 415 | "source": [ |
345 | | - "## Code solution here." |
| 416 | + "## Code solution here" |
346 | 417 | ] |
347 | 418 | }, |
348 | 419 | { |
349 | 420 | "cell_type": "markdown", |
350 | 421 | "metadata": {}, |
351 | 422 | "source": [ |
352 | | - "**Exercise 4:** Lets revisit a problem we saw earlier to see how the technique of least squares compares to our previous method of interpolation. Here are the average radii of the orbits of the planets in our solar system, and their average orbital velocity around the Sun.\n", |
| 423 | + "**Exercise 4:** The following example of a database with webpages containing the content related to Global Warming. The set of searchable keywords is: **\\{causes, effects, global, warming, fossil-fuels, climate , potentials, change, actions, prevent \\}**\n", |
353 | 424 | "\n", |
354 | | - "|Planet | Distance from Sun (million km) | Orbital Velocity (km/s) |\n", |
355 | | - "| ------------------------------- | ------------------------------- | ------------------------------- |\n", |
356 | | - "|Mercury | 57.9 | 47.4 |\n", |
357 | | - "|Venus | 108.2 | 35.0 | \n", |
358 | | - "|Earth | 149.6 | 29.8 |\n", |
359 | | - "|Mars | 228.0 | 24.1 |\n", |
360 | | - "|Jupiter | 778.5 | 13.1 |\n", |
361 | | - "|Saturn | 1432.0 | 9.7 |\n", |
362 | | - "|Uranus | 2867.0 | 6.8 |\n", |
363 | | - "|Neptune | 4515.0 | 5.4 |\n", |
| 425 | + "Some titles in this database are as follows:\n", |
364 | 426 | "\n", |
365 | | - "$(a)$ Use the method of least squares to find the cubic polynomial of best fit for these points. Plot the data points together with the graph of the polynomial to observe the fit.\n", |
| 427 | + "- Causes of Global Warming\n", |
| 428 | + "- Global Warming vs Climate change\n", |
| 429 | + "- Fossil Fuels - A Major cause of Global Warming\n", |
| 430 | + "- Actions to prevent Global Warming\n", |
| 431 | + "- Potentials of Global Warming\n", |
| 432 | + "- Effects of Global Warming\n", |
366 | 433 | "\n", |
367 | | - "$(b)$ The dwarf planet Ceres has an average distance from the sun of 413.5 million km. What does the polynomial suggest the value would be? How closely does this agree with what the points seem to suggest?" |
| 434 | + "Suppose the keywords we want to search are \"potentials\", \"global\" and \"warming\". Create the search vector and database matrix. Analyse the resulting vector to find the webpage containing the most relevant information." |
368 | 435 | ] |
369 | 436 | }, |
370 | 437 | { |
371 | 438 | "cell_type": "code", |
372 | | - "execution_count": null, |
| 439 | + "execution_count": 18, |
373 | 440 | "metadata": {}, |
374 | 441 | "outputs": [], |
375 | 442 | "source": [ |
376 | | - "## Code solution here." |
| 443 | + "## Code solution here" |
377 | 444 | ] |
378 | 445 | }, |
379 | 446 | { |
|
0 commit comments