Introduction to Numerical Methods


Introduction to Numerical Methods

Corey
Welcome! Today we’re building a toolkit for numerical methods: ways to get useful answers when exact, analytical solutions are too difficult, too slow, or unavailable. We’ll start with the basic idea, then connect it to linear systems, root-finding, and interpolation.

Anna
Let’s make the key distinction first. An analytical method follows mathematical steps that produce an exact answer, when those steps are available. For example, from x plus one equals zero, subtract one from both sides and get x equals negative one.

Corey
Numerical methods take a different approach. We try inputs, inspect the outputs, adjust our inputs, and repeat until the result is close enough for our needs. The answer is an approximation, and we trade computation time for accuracy: more computation can often bring us closer.

Anna
That may sound inefficient for a simple equation, but it becomes valuable when analytical work would take hours or cannot be completed at all. A computer can repeat calculations far more readily than we can by hand. The central question becomes: how close is close enough?

Corey
A major application in this course is solving systems of linear equations. A system is a collection of independent linear equations that share the same variables. Independence matters: x plus seven equals zero and x equals negative seven are not two independent equations; one is just a rearrangement of the other.

Anna
And what makes an equation linear? Each term is either a constant or a constant multiplied by a variable. So an equation such as a-one times x-one plus a-two times x-two plus b equals zero is linear, because the a’s and b are constants.

Corey
A squared variable, like x squared, breaks that rule and makes an equation nonlinear. Solving a linear system means assigning values to its unknown variables so that all the equations hold at once. The full collection of valid assignments is called the solution set.

Anna
There are three possibilities for that set. The equations might meet at one point, giving a single unique solution; they might overlap in a way that allows infinitely many solutions; or they might never all meet, giving no solution. Graphing can make those possibilities easier to picture.

Corey
For larger systems, matrices give us a compact way to organize the equations. In A times x equals b, matrix A stores the variable coefficients, vector x stores the unknowns, and vector b stores the constants. The number of rows in A corresponds to the equations, and the number of columns corresponds to the variables.

Anna
An augmented matrix is another way to display the same system. It places the coefficient entries alongside the constants, separated by a line, so we can see the whole system without repeatedly writing the variables. One important caution: having more unknowns than equations means we cannot expect a unique solution from the system alone; it does not automatically prove that no solutions exist.

Corey
Now let’s connect solutions to singular matrices. A singular matrix is square and non-invertible, so its determinant is zero. In the system A x equals b, that means there is no unique solution: depending on b, there may be no solution or infinitely many.

Anna
The determinant also has a geometric interpretation. In two dimensions, it describes the area-scaling factor of a transformation; in three dimensions, it describes volume scaling. If the determinant is zero, an area or volume gets collapsed, which helps explain why the transformation loses information and the matrix cannot be inverted.

Corey
That geometric idea connects to the graph of a linear system. If a transformation collapses dimensions, equations may cease to meet at one unique point. For a special triangular matrix, the determinant is especially easy to find: multiply the entries on the main diagonal. A zero on that diagonal makes the determinant zero.

Anna
That brings us to special matrices, which are useful because they’re easier to solve than a general matrix. An identity matrix has ones on its diagonal and zeros elsewhere; it represents a system already solved, so each unknown directly matches the corresponding constant in b.

Corey
A diagonal matrix has zeros everywhere off the main diagonal, but its diagonal entries don’t all have to be one. Each equation contains just one unknown, so divide the corresponding constant by that unknown’s coefficient to solve it.

Anna
An upper triangular matrix has zeros below the main diagonal. Start with the last row, solve its one remaining unknown, then substitute that value into the row above. Keep moving upward; that is backward substitution.

Corey
A lower triangular matrix has zeros above the diagonal, so we work in the opposite direction. Solve the first row and move down, using known values as we go. That’s forward substitution. Triangular forms are often a practical target because they’re simpler to reach than a fully diagonal or identity matrix.

Anna
Gaussian elimination is the direct method that transforms a system into upper triangular form, then uses backward substitution. First, write the augmented matrix. Next, use row operations to turn entries below each diagonal pivot into zero, moving from the left column toward the right.

Corey
To eliminate an entry, scale the pivot row by the appropriate factor and subtract it from the row you’re changing. Apply the same operation across the entire row, including the constant column, so the equation stays equivalent. Once the matrix is upper triangular, solve from the bottom up.

Anna
A zero pivot needs attention before you divide by it. If another row has a suitable nonzero entry in that column, swap the rows. For example, the equations 7x plus 9y equals 2 and 2y equals 6 are easy to solve after placing the second equation first: y is 3, then x is negative twenty-five sevenths.

Corey
Here’s another two-by-two example: 2x plus 3y equals 4, and 4x plus 9y equals 6. Eliminate the x entry in the second row, solve the resulting equation for y, then substitute upward; the result is y equals negative two-thirds and x equals three.

Anna
And check your result by putting both values back into the original equations. If each left side equals its right side, the solution passes that check. If a zero pivot cannot be replaced by a suitable row swap, elimination may reveal that the system is singular or does not have a unique solution.

Corey
Partial pivoting makes elimination more numerically reliable. Before eliminating in a column, compare the absolute values of the candidate entries in that column, starting at the pivot row. If a larger entry is available below, swap rows so the pivot has the largest absolute value available.

Anna
Why do that? Elimination uses the pivot in scaling factors, and dividing by a very small number can magnify round-off error. Choosing a larger pivot helps reduce that risk and avoids a zero pivot when possible. Partial pivoting changes row order, not the order of the variables; complete pivoting can also swap columns.

Corey
In one three-equation example from the course, pivoting starts by moving the row with a larger first-column entry into the pivot position, then checks the next column and may swap again. After elimination, backward substitution gives approximate values for the variables, which should be checked in the original equations.

Anna
LU factorization builds on elimination. We write the original coefficient matrix A as L times U, where L is lower triangular and records the elimination scaling factors, and U is upper triangular. The key is to keep track of those factors as elimination creates zeros.

Corey
To solve A x equals b, first solve L c equals b by forward substitution. Then solve U x equals c by backward substitution. If A stays the same but b changes, we can reuse L and U rather than repeating the computationally demanding elimination.

Anna
That makes LU especially helpful when we have many right-hand-side vectors b for the same coefficient matrix. It also simplifies the determinant: the determinant of A is the product of the determinants of L and U, and for triangular matrices each determinant is the product of its diagonal entries.

Corey
Gaussian elimination and LU factorization are examples of direct methods. A direct method follows a finite sequence of operations designed to produce a solution, such as forming an augmented matrix, eliminating entries, and substituting. It doesn’t give a usable answer halfway through that required sequence.

Anna
Iterative methods work differently. They begin with a guess and repeatedly improve it; we can stop when the error is small enough for our purpose. They’re often attractive for large systems because they break the work into smaller repeated steps, rather than working with the full matrix in the same way as a direct method.

Corey
The general idea is to start from A x equals b and rearrange the equations so we can calculate a new estimate for each unknown. The mismatch between A times our current guess and b is a residual. Iterative methods aim to reduce that mismatch until the result is sufficiently accurate.

Anna
The starting guess matters: a better one may mean fewer iterations. But iterative methods don’t automatically converge for every system. Before relying on an answer, we need conditions or checks that give us confidence the process is approaching a solution.

Corey
One useful condition is diagonal dominance. For each row of a square matrix, take the absolute value of the diagonal entry and compare it with the sum of the absolute values of the other entries in that row. The diagonal entry must be at least as large in every row, and strictly larger in at least one row.

Anna
The comparison is row by row, not against the whole matrix at once. If all the diagonal entries merely equal their corresponding sums, the strict condition hasn’t been met. Under the condition just described, Jacobi and Gauss-Seidel iteration are guaranteed to converge to a unique solution for the linear system.

Corey
Jacobi iteration begins with a guess for every unknown, often all zeros if we have no better information. Rearrange each equation to solve for a different variable. Then calculate each new variable using values from the previous iteration only.

Anna
After one full pass, those new values become the next set of guesses. Repeat, and check the equations or residuals to see whether the errors are below your tolerance. In a three-variable problem, that means keeping track of all three estimates at each iteration, not just the one that looks closest.

Corey
Gauss-Seidel uses the same rearranged equations, but updates variables immediately. When solving for the second variable, use the newly calculated first-variable value; when solving for the third, use the latest first and second values.

Anna
That reuse of fresh estimates is the main difference from Jacobi. It often reaches an acceptable answer in fewer iterations, though convergence still needs to be considered. Both methods are tedious by hand, so a spreadsheet or program can make the repeated calculations and error checks easier.

Corey
When setting up Excel or Google Sheets, keep the coefficients fixed in the formulas as you copy them down through iterations. A practical check is to substitute each current set of estimates into the original equations and see whether the discrepancies are within tolerance.

Anna
Now we’ll shift from linear systems to nonlinear equations. A linear equation uses constants and constants times variables; a squared variable, for example, makes an equation nonlinear. Solving for a root means finding an input where the function’s output is zero—the point where its graph crosses the x-axis.

Corey
Root-finding methods come in two broad types. Closed methods start with lower and upper bounds that bracket a root. Open methods start with one or more guesses and use those to move toward a root, without requiring a bracketing interval.

Anna
Closed methods are useful when we can find appropriate bounds, but we need to be careful: the interval should contain a single root for the procedures we’re discussing. Open methods can be faster, but their guesses may lead them away from a root instead. Plotting the function can help us choose a sensible interval or starting point.

Corey
The bisection method is a closed method. Start with a and b where the function values have opposite signs; equivalently, their product is less than zero. That sign change tells us there is at least one root between them, provided the function is continuous over the interval.

Anna
Take the midpoint, c equals a plus b divided by two, and check which half still has opposite-sign endpoint values. Keep that half and repeat. Each iteration halves the interval, and its width gives a straightforward measure of how tightly the root is bracketed.

Corey
For example, the function 4x squared plus 3x minus 3 has a root between zero and one, because the endpoint outputs have opposite signs. Repeated bisection narrows the interval around the positive root, which is about 0.593. Stop when the interval width is below the requested error tolerance.

Anna
A sign change is a useful bracket test, but it doesn’t tell us that there’s exactly one root in the interval. If there are multiple roots, a method may not isolate the one we want. A graph can help us inspect the interval and choose a bracket around a single root.

Corey
False position, also called regula falsi, uses the same bracketing idea but chooses a different next point. Instead of taking the midpoint, draw a straight line between the two endpoint values and use where that line crosses the x-axis as the new estimate.

Anna
Then test the new point’s function value against the two endpoint values, keep the pair with opposite signs, and repeat. This often moves faster than bisection, though it still depends on a good bracket and can behave unevenly if one boundary barely moves.

Corey
For the same quadratic on the interval from zero to one, the false-position estimate comes from the secant line through the endpoint values. The example reaches an estimate near the positive root in fewer iterations than bisection. In a spreadsheet, track the endpoints, their function values, the new estimate, and the change in successive estimates.

Anna
Newton’s method is an open method that uses a tangent. Start with a guess x, evaluate the function and its derivative there, and move to where the tangent line crosses the x-axis. The update is: new x equals current x minus f of x divided by f-prime of x.

Corey
The tangent comes from a first-order Taylor approximation of the function near the current guess. Because each new guess is built from the local slope, Newton’s method can converge very quickly when the starting point is suitable and the tangent behavior is well behaved.

Anna
But there’s no general guarantee it will converge. A poor starting guess, a problematic slope, or a function with step-like behavior can send estimates away from the root, or make the update unusable if the derivative is zero. Plotting first can help us pick a better guess.

Corey
For f of x equals x squared minus two, starting at two gives a first Newton estimate of 1.5, then about 1.416, then about 1.414. The sequence approaches the positive root, square root of two. That’s a nice demonstration of how quickly the method can refine a good starting point.

Anna
The secant method resembles Newton’s method but estimates the slope using two function points instead of calculating a derivative. Start with two guesses, draw the secant line through their graph points, and use its x-intercept as the next estimate.

Corey
That new estimate and one of the previous points provide the next pair; keep repeating until the change is acceptably small. Since the method uses a secant through two points, it needs two starting guesses. It may be a little slower than Newton’s method, but it avoids requiring an explicit derivative.

Anna
For f of x equals x squared minus three, the example starts from one and three. Successive secant estimates are about 1.5, 1.667, and 1.736, moving toward the positive root, about 1.732. As with other open methods, sensible starting guesses help.

Corey
Fixed-point iteration begins by rewriting the root-finding equation in the form x equals g of x. Then choose an initial guess and repeatedly calculate the next estimate as g of the previous one. A root of the original function is a fixed point when this equality holds.

Anna
There may be more than one way to rearrange the same equation, and those choices can behave very differently. A useful local convergence test is that the absolute value of g-prime stays below one near the fixed point. If the slope’s absolute value is greater than one there, the iteration will move away rather than settle in.

Corey
For the equation e to the power of one-half x minus x minus two equals zero, two rearrangements are g-one equals e to the power of one-half x minus two, and g-two equals two times the natural log of x plus two. The graph suggests the second rearrangement has too steep a slope near the root, so it does not converge there.

Anna
Using g-one and starting at two, the estimates proceed roughly 0.718, negative 0.568, negative 1.248, negative 1.464, and negative 1.519. That last value is near the root, approximately negative 1.52. Track the difference between successive estimates, and choose the rearrangement and starting point carefully.

Corey
Our final topic is interpolation: using known data points to estimate values between them. Instead of measuring a system at every possible input, we collect enough data to describe it and build a continuous function that fills in the gaps.

Anna
Think of recording a pot of water’s temperature at a few times. If we want its temperature at an intermediate time, an interpolation function gives an estimate based on the known measurements. The estimate is most naturally used within the range of the data points we have.

Corey
Lagrange polynomials are one way to build that function. With n data points, the interpolating polynomial has degree at most n minus one: two points give a first-degree polynomial, three give a second-degree polynomial, and four give a third-degree polynomial.

Anna
The construction adds one term for each data point. Each term is designed to equal that point’s y-value at its own x-coordinate and to vanish at the other data points. That’s why the finished polynomial passes through every supplied point.

Corey
For a simple first-order example, two data points produce the line five x minus five. Evaluate it at 2.2 and the estimated output is six. With three points, the example polynomial is negative 0.25 x squared plus 3x plus 1.25; at x equals 2.5, it gives 7.1875.

Anna
With four points, the example builds a third-degree polynomial: about 0.25 x cubed minus 1.5833 x squared plus 5x plus 0.33. At x equals three, it gives approximately 7.833. A good check is to plug each original x-coordinate into the polynomial and make sure it returns the original y-value.

Corey
Newton’s divided-difference method is another way to form an interpolating polynomial. Its coefficients are calculated from the data in a divided-difference table. For two points, the first divided difference is the change in y divided by the change in x—the slope between them.

Anna
For higher-order polynomials, each new divided difference is built from differences at the previous order. This creates a recursive table, and its entries supply the coefficients in Newton’s polynomial. One advantage is that adding another data point can extend the polynomial without rebuilding all the earlier terms.

Corey
In the first-order example, the divided-difference polynomial simplifies to five-thirds x plus four-thirds, and it estimates an output of about 4.667 at x equals two. In the second-order example, three points give negative 0.375 x squared plus 3.5x minus 1.125; at x equals four, the result is 6.875.

Anna
So the big picture is that numerical methods help us compute useful approximations across several kinds of problems. Direct methods transform linear systems in a finite sequence; iterative methods improve guesses; root-finding methods locate where functions equal zero; and interpolation estimates values between known data points.

Corey
And throughout, keep asking three questions: what assumptions does this method need, how will I know whether it’s converging, and what error is acceptable for my task? Those questions turn formulas into reliable tools. Thanks for learning with us.

Ask anything
We've read this whole study set, so questions about it get the best answers.