lecutre 7: System of nonlinear equations
Overview
Professor Saad Explains shows how to solve coupled nonlinear systems with SciPy's `optimize.root`, first defining residual vectors and initial guesses, then applying the method to a finite-difference heat-transfer model with a fourth-power radiation term. A 100-point temperature system demonstrates NumPy slicing, boundary-condition checks, and limiting-case verification; the closing discussion distinguishes interpolation from regression for clean physical data versus variable real-world measurements.
Key takeaways
- A coupled system is solved by finding a vector of unknowns that makes every residual zero; SciPy's `optimize.root` accepts both the residual-vector function and a matching vector of initial guesses.
- Initial guesses should reflect the physics: the radiation example starts with plausible temperatures, and time-dependent solvers can reuse the previous time step's solution.
- For the 100-point rod model, fixed endpoints require residuals T0 − TL and T(N−1) − TR, while each interior equation couples neighboring temperatures through a fourth-power radiation term.
- NumPy slices `T[:-2]`, `T[1:-1]`, and `T[2:]` align neighboring grid values and compute all interior residuals at once, avoiding explicit indexing loops.
- Boundary-condition checks and limiting cases such as α = 0 and large α provide useful initial verification; comparison with an analytical special case gives a more rigorous error assessment.
- Interpolation hits every data point, while regression estimates a trend; regression is often more suitable for scattered measurements such as human height versus femur length.
Chapters
- The lesson shifts from single algebraic equations to coupled systems, which commonly arise after modeling engineering or physics problems.
- A one-dimensional rod with fixed end temperatures and a radiation environment has a temperature-to-the-fourth-power term, unlike the linear temperature difference used in a convection example.
- Radiation exchange can throttle heating as the material approaches the environment temperature, giving the model a physical equilibrium mechanism.
- For two equations in x and y, solving the system means finding points where both curves intersect.
- Moving each equation's terms to one side creates residual functions, and a solution makes every residual equal to zero.
- The intersection picture helps explain systems, but larger systems such as the rod model require solving many coupled equations together.
- For N equations and N unknowns, collect the unknowns as a vector x and the residuals as a vector R(x).
- The rod temperatures T0 through T(N−1) are the unknowns, while each grid point contributes a residual equation.
- A consistent ordering of variables and residuals makes it clear which returned solution corresponds to each unknown.
- The example system uses residuals based on 0.5x³ + y − 4x and y − sin(x)e^(−x).
- A Python function unpacks the input vector into x and y, calculates both residuals, and returns them in a NumPy array.
- `scipy.optimize.root` takes the residual function and a vector of initial guesses, with one initial value for each unknown.
- The in-class Jupyter notebook imports NumPy, Matplotlib, and `scipy.optimize.root` to evaluate residuals and find solutions.
- Different starting points lead the solver toward different intersections, including a root near (−1.461, −4.285), the origin, and one near (2.826, 1.83).
- The solver finds one root per call, so locating multiple roots requires additional runs with different initial guesses.
- For the heat-transfer system, reasonable starting temperatures include values between the boundary temperatures, their average, or the radiation temperature.
- Physical intuition can rule out implausible solutions, such as temperatures far outside the expected range.
- For a slowly changing time-dependent problem, the previous time step's solution can serve as the next initial guess.
- The discretized second derivative couples each interior temperature to its neighbors, so the grid equations form one system rather than independent scalar problems.
- Interior residuals combine T(i+1) − 2Ti + T(i−1) with a radiation term proportional to αΔx²(Ti⁴ − T∞⁴).
- Boundary equations become residuals T0 − TL and T(N−1) − TR, keeping the full system at N equations for N temperature unknowns.
- The example uses a rod length L of 1 meter and N = 100 grid points, with spacing Δx = L/(N−1).
- The example boundary temperatures are TL = 350 K and TR = 300 K, with a radiation environment T∞ = 450 K.
- The parameter α controls the strength of radiation's influence on the temperature profile.
- The residual routine receives the temperature array T and initializes an output array with `np.zeros_like(T)`.
- Using `zeros_like` ties the residual-array size directly to the supplied temperature vector rather than a separately maintained N.
- The first and last residual entries encode the fixed boundary temperatures; interior entries follow the finite-difference equation.
- The interior residuals correspond to indices 1 through N−2, selected with the slice `R[1:-1]`.
- Slices `T[:-2]`, `T[1:-1]`, and `T[2:]` align the left neighbor, current point, and right neighbor arrays.
- Because the slices have matching lengths, NumPy evaluates the finite-difference residual pointwise without an explicit loop.
- The solver starts with an initial vector of N temperatures, set in the demonstration to the 450 K radiation environment.
- The returned solution is plotted against the rod's spatial grid, and the endpoints are checked against 350 K and 300 K.
- With the initial α = 10⁻⁷ example, the interior temperature approaches but does not reach 450 K.
- At α = 0, the radiation term disappears and the temperature profile becomes a straight line between the boundary values.
- For larger α, the rod's interior is pulled closer to T∞, while the ends still satisfy their fixed boundary conditions.
- The lecture notes that a nonlinear solver can solve a linear special case, though the demonstrated iterative method may take many iterations.
- The example varies the radiation environment and boundary temperatures to show heating and cooling trends in the computed profile.
- Back-of-the-envelope checks include confirming boundary values and testing expected behavior at α = 0 and at large α.
- A stronger verification would compare against an analytical solution for a special case and calculate the resulting error.
- Interpolation passes through every data point, which is appropriate when the measured values are trusted as exact but can create oscillations with high-order polynomials.
- Regression models an overall trend rather than forcing a fit through every measurement, making it useful when observations vary or contain noise.
- Human height versus femur length illustrates real-world scatter: similar femur lengths can correspond to different heights, unlike a physical relation such as density versus temperature under fixed conditions.
Transcript excerpt
0:00 Let's begin. Uh we are almost done with the algebraic equations. Uh we will finish off with systems of nonlinear equations. And again, this part of the of the course is focused on getting you the tools or refreshing your mind about the tools that you need to have to solve things to solve equations. Right? I argued last time as an as an engineer, as a scientist, you have a bachelor's degree. Yeah, somebody gives you a problem or an equation, you need to be able to know how to solve it or know how to plan to attack it, know what you need to do to just get a solution whether you know the tool or not. But thinking about that problem,
0:48 thinking about the equation and so which is harder? Let me ask you this. Which is harder? math if I give you a mathematical equation or if a physics problem like consider two rea two reactants you know with a bilinear reaction a plus b going to c etc and they're diffusing in these which which is easier to deal with a problem statement like that or I give you solve this equation which do you math math math okay math math physics physics Okay. So, we have this is not a democracy, but but I guess there's an opinion here, of course. Okay. Yeah. But I'll make an argument for one or the other. Um, any preference? Which one
1:36 when you're if I tell you solve this equation versus here's a bunch of stuff and which one do you think is easier? The math. Okay. For those who argued math, why is it easier? Okay. Why do you think the physics is easier? >> I meant to say the physics is harder. >> Oh, you meant the physics is harder.
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Professor Saad Explains.