lecture 3: Error Analysis, linear systems 1
Overview
The lecture completes numerical error analysis by showing how NumPy arrays and slicing compute forward-difference derivatives and successive relative errors efficiently, then introduces Lp norms for measuring collections of errors. It begins linear systems by distinguishing algebraic from differential equations, defining linearity, and connecting conservation laws and computational fluid dynamics to systems of algebraic equations, with a steady-state reactor example setting up the next class.
Key takeaways
- For adjacent forward-difference estimates, derivs[1:] and derivs[:-1] have equal lengths, so NumPy can compute every successive relative error with one vectorized expression.
- NumPy's np.linalg.norm uses the ℓ2 norm by default; ord=1 selects the ℓ1 norm, and ord=np.inf selects the largest absolute array entry.
- The ℓ-infinity norm can reveal a single severe error that may be obscured when many small errors are aggregated with an ℓ2 norm.
- An algebraic equation is linear in its unknowns only when they appear to the first power, outside functions, and without multiplication or division by other unknowns.
- Discretizing fluid-flow conservation equations on a computational grid turns field variables such as temperature and pressure into a system of algebraic equations.
- In a steady-state reactor, conservation of solute mass gives C1Q1 + C2Q2 = C3Q3, where concentration times volumetric flow rate has units of mass per time.
Chapters
- The example estimates the derivative of 2e^(x/2) at x = 3 with the forward Euler, or forward-difference, formula.
- Using successively smaller step sizes h gives a sequence of approximations, but the true derivative is assumed unknown.
- The goal is to estimate error by comparing successive derivative approximations and report relative error.
- Python arrays use zero-based indexing, and negative indices such as A[-1] access entries from the end.
- A[start:stop] includes the start index and excludes the stop index, so A[0:2] returns the first two entries.
- Slices such as A[3:] and A[:2] access the remainder or beginning of an array without requiring its length.
- Storing h values in a NumPy array lets NumPy functions such as exp evaluate the same operation across every entry.
- The derivative formula can be applied to an entire array of step sizes at once, returning an equally sized array of approximations.
- Vectorized array operations replace repetitive copy-and-paste calculations or an explicit Python for loop.
- Successive-error calculations compare adjacent derivative estimates, so the two aligned slices are derivs[1:] and derivs[:-1].
- Both slices have the same length, allowing elementwise subtraction and division in a single NumPy expression.
- The relative approximate error uses the difference between successive estimates divided by the newer, better estimate.
- The example stores h values 8, 4, 2, 1, 0.5, 0.25, 0.125, and 0.0625 in a NumPy array.
- With x set to 3.0, NumPy computes all forward-difference derivatives in one array operation.
- The notebook forms errors from shifted derivative slices, then takes the absolute value and multiplies by 100 for percentage relative error.
- True error is available when a reference answer is known, while approximate error compares successive numerical estimates.
- Approximate error is useful in practice when testing an algorithm without knowing the exact derivative or solution.
- The lecturer relates the choice of error measure to verification and validation, noting that some difficult problems lack a known true answer.
- A GPS example gives offsets of 2.3 m south and 1.2 m east from a coffee-shop door.
- Possible aggregate error measures include adding the components, averaging them, using Pythagorean distance, or selecting the largest component.
- The example motivates norms as different ways to summarize a list or vector of errors rather than relying on one universal measure.
- The lowercase ℓ1 norm is the sum of the absolute values of the entries in an array.
- The ℓ2 norm is the square root of the sum of squared entries, extending Pythagorean distance to many dimensions.
- The ℓ-infinity norm reports the largest absolute entry, making it useful for detecting a localized worst-case error.
- NumPy computes array norms with np.linalg.norm, using the ℓ2 norm by default.
- Passing ord=1 or ord=3 selects those norms, while ord=np.inf requests the maximum absolute entry.
- The lecture recommends ℓ2 and ℓ-infinity as common numerical-computing choices, while emphasizing that application requirements or theorems may determine the appropriate norm.
- The lecture transitions from error analysis to equations as core tools for modeling, computation, and research.
- A sofa delivery anecdote illustrates how a 4-inch measurement mismatch can invalidate a plan despite advance measurements.
- The course aims to bring graduate students with varied coding and theory backgrounds toward shared tools for solving equations.
- Algebraic equations contain no derivatives or integrals, unlike differential equations.
- Examples include 2x + 3y = 0 and cos(u) = 0.1; equations may involve one or many unknowns.
- A variable appears linearly when it is not raised to a power, placed inside a function such as sine or an exponential, or multiplied or divided by another unknown.
- A NIST analysis examines a 2012 wind-driven house fire in Riverdale Heights, Maryland, in which seven firefighters were injured.
- The Fire Dynamics Simulator, or FDS, models the fire, and Smokeview visualizes its results; the simulation used a steady 20 mph wind and an estimated peak heat-release rate of about 9 MW.
- A computational fluid dynamics grid assigns variables such as temperature to grid points, and discretized conservation equations produce algebraic systems to solve.
- An equation with derivatives of unknowns is differential; an algebraic equation has no derivatives or integrals of the unknowns.
- A linear equation has unknowns only to the first power, not multiplied or divided by other unknowns and not inside functions such as logarithms or exponentials.
- For example, xy + y = 3 is nonlinear because x and y are coupled through multiplication, while 2x = 5 is linear in x.
- A system combines multiple linear equations involving two or more unknowns, which can represent physical quantities such as temperature, velocity, pressure, or concentration.
- Conservation of mass is expressed as accumulation equals inputs minus outputs.
- For a changing system, these quantities are rates, such as kilograms per second, and accumulation corresponds to the time rate of change of material inside the system.
- When a bucket or process is at steady state, inputs equal outputs and the accumulation rate is zero.
- For a perfectly mixed reactor, solute mass flow is concentration times volumetric flow rate, giving C1Q1 + C2Q2 = C3Q3.
- The reactor balance sets up a system of linear equations in concentrations and flow rates for the next lecture.
Transcript excerpt
0:00 Let's begin. I wanted to share this with you especially now that you're starting on your graduate journey. Okay? So you are now the you might you're here. Okay? But don't judge yourself too early in the process because you're going to get there and be a diamond when you're done. Okay? And diamonds are forever. Right? Okay. So I'll continue with the example we were working on last time and we're still kind of just dragging our feet, taking it easy as as we build our as we build rapport and give you a chance to get used to Python and do some work on your own to catch up with Python coding. And last we left off was looking at this example. We wanted to use
0:49 we were talking about errors and we wanted to evaluate the error in approximating the first derivative with this formula. It's called the forward Euler formula. Rise over run is the definition of the derivative. We just drop the limit. Um the definition of the derivative is that this approximation is exact when h approaches zero. Um but when you drop the limit and you pick a small number for h, it's a pretty darn good approximation to the derivative. Now how good it is? Well we don't know because we're assuming we don't know the true value of the derivative. Right? And so we want to evaluate the approximate error and I asked you to do this approximation for this function 2e to the 1/2x at this point x = 3. But we're going to be using these different values for h and
1:38 the approximate error we're measuring a good approximation versus a worse approximation. Right? So that difference gives us an idea of what the error is. And we want to report the percent
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.