{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Nonlinear Equations\n", "\n", "## Overview, Objectives, and Key Terms\n", "\n", "In [Lesson 19](L19_NumericalDifferentiation.ipynb), finite differences gave us practical derivative estimates, including central differences and complex-step derivatives for callable functions. Here, derivatives become part of an iteration: we solve nonlinear equations by repeatedly asking how the residual changes.\n", "\n", "A scalar nonlinear equation has the form\n", "\n", "$$\n", " f(x)=0.\n", "$$\n", "\n", "A system of nonlinear equations has the form\n", "\n", "$$\n", " \\mathbf{f}(\\mathbf{x})=\\mathbf{0}.\n", "$$\n", "\n", "For a system, the derivative object is the **Jacobian matrix**. Each row of the Jacobian is the gradient of one residual component. That connection is the main reason the gradient material from Lesson 19 helps here.\n", "\n", "### Objectives\n", "\n", "By the end of this lesson, you should be able to\n", "\n", "- Use plots and signs to isolate roots of scalar nonlinear equations.\n", "- Implement and interpret bisection as a bracketing method.\n", "- Use Newton's method when derivative information is available.\n", "- Use finite-difference or complex-step derivative estimates when an analytic derivative is inconvenient.\n", "- Interpret a Jacobian as one gradient per residual equation in a nonlinear system.\n", "- Use `scipy.optimize.fsolve` for scalar equations and small nonlinear systems.\n", "\n", "### Key Terms\n", "\n", "- nonlinear equation\n", "- residual\n", "- root\n", "- bracket\n", "- bisection\n", "- Newton's method\n", "- secant method\n", "- convergence\n", "- derivative estimate\n", "- Jacobian matrix\n", "- nonlinear system\n", "- `scipy.optimize.fsolve`\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Nonlinear Equations\n", "\n", "Linear equations are characterized by *linear combinations* or the unknowns. For example, the system of equations for $x$ and $y$\n", "\n", "$$\n", "\\begin{split}\n", " ax + by &= 1 \\\\\n", " cx + dy &= 2 \n", "\\end{split}\n", "$$\n", "\n", "is linear because $x$ and $y$ appear with only constant coefficients. There are no $x^2$ terms, or $\\sin(y)$ terms. Just multiples of $x$ and $y$. Any deviation from this pattern results in **nonlinear equations**. For example, quadratic equation $ax^2 + bx + c = 0$ is nonlinear, and we know how to find the **roots** of this equations. A root is the solution $x$ to any equation (generally, nonlinear) $f(x) = 0$. Our goal now is to solve such equations using the tools at our disposal." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Analytic Solutions\n", "\n", "In rare cases, nonlinear equations have closed-form solutions (i.e., you can write it down explicitly). The quadratic equation is one example. In fact, solutions exist for the general cubic (add a $x^3$ term) and quartic (add both $x^3$ and $x^4$). The roots are hideous (compared to the quadratic equation roots), but they are known. \n", "\n", "