{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercises on Root-finding Without Derivatives"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercise 1: Comparing Root-finding Methods\n",
"\n",
"**Note:** This builds on the previous exercise comparing the Bisection and Newton's Methods;\n",
"just adding the Secant Method.\n",
"\n",
"A) Write a Python function implementing the secant method with usage\n",
"\n",
" (root, errorEstimate, iterations, functionEvaluations) = secant(f, a, b, errorTolerance, maxIterations)\n",
"\n",
"Update your previous implementations of the bisection method and Newton's method to mimic this interfacce:\n",
"\n",
" (root, errorEstimate, iterations, functionEvaluations) = bisection(f, a, b, errorTolerance, maxIterations)\n",
" \n",
" (root, errorEstimate, iterations, functionEvaluations) = newton(f, x_0, errorTolerance, maxIterations)\n",
"\n",
"**Aside:** the last parameter `maxIterations` could be optional, with a default like `maxIterations=100`.\n",
"\n",
"B) Use these to solve the equation\n",
"\n",
"$$ 10 - 2x + \\sin(x) = 0 $$\n",
"\n",
"i) with [estimated] absolute error of no more than $10^{-8}$, and then\n",
"\n",
"ii) with [estimated] absolute error of no more than $10^{-15}$.\n",
"\n",
"Note in particular how many iterations and how many function evaluations are needed.\n",
"\n",
"C) Discuss: rank these methods for speed, as indicated by these experiments, and explain your ranking."
]
},
{
"cell_type": "raw",
"metadata": {
"tags": []
},
"source": [
"---\n",
"This work is licensed under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 4
}