rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · cubic splines cubic splines: 3rd order...

60
PHY 688: Numerical Methods for (Astro)Physics Roots

Upload: others

Post on 13-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Roots

Page 2: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Root Finding● Basic methods can be understood by looking at the function

graphically

– Function f(x) has a zero at x⋆

– Note the sign of f(x) changes at the root

Page 3: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Bisection● Simplest method: bisection

– Evaluate at x1 and x2 : f(x1) and f(x2) – If these are different signs, then the root lies between them

– Evaluate at the midpoint: xm = (x1 + x2)/2 getting f(xm) – The root lies in one of the two intervals—repeat the process

Page 4: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Bisection● Need two initial points (guesses) that you believe bound the root

– If there are two roots in-between, then you are in trouble

– Some pathological cases: e.g. f(x) = x2 ● Convergence can be slow—each iteration reduces the error by a

factor of 2

Page 5: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Bisection

Page 6: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Newton-Raphson● If we know df/dx we can do better

– Start with an initial guess, x0, that is “close” to the root– Taylor expansion:

– If we are close, then

– Update

– We can continue, iterating again and again, until the change in the root < ε

● Converges fast: usually only a few iterations are needed

Page 7: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Newton-Raphson

Page 8: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Newton-Raphson● Requirements for good convergence:

– Derivative must exists and be non-zero in the interval near the root– Second derivative must be finite– x0 must be close to the root

● Can be used with systems (we'll see this later)● Multiple roots?

– Generally: try to start with a good estimate*

*not a guarantee

Page 9: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Newton-Raphson● Basins

– Consider q(x) = x3 { 2x2 { 11 x + 12 (example from Wikipedia / Dence, T. 1997)

x0 root2.35287527 4.02.35284172 -3.02.35283735 4.02.352836327 -3.02.352836323 1.0

(Wikipedia)

Page 10: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Newton-Raphson● Consider f(x) = x3 { 2x +2

– Start with 0 → 1 → 0 → 1 → 0 ...– Cycle

(wikipedia)

(Wikipedia)

Page 11: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Secant Method● If we don't know df/dx , we can still use the same ideas

– We need to initial guesses: x{1 and x0 – Use approximate derivative

● Used when an analytic derivative is unavailable, or too expensive to compute (e.g. EOS)

Page 12: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Practical Notes● N-R is used successfully with equations of state

– Function takes ρ, T and we want to come in with P, ρ– Requires well-behaved derivatives and an initial guess

● Secant method is used, for example, in Riemann solvers in hydrodynamics, where EOS evaluations can be expensive or the derivative may not be known

Page 13: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Interpolation

Page 14: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Interpolation● As we've seen, we frequent have data only at a discrete number of

points– Interpolation fills in the gaps by making an assumption about the

behavior of the functional form of the data● Many different types of interpolation exist

– Some ensure no new extrema are introduced– Some match derivatives at end points– ...

● Generally speaking: you need to balance the number of points used (which can increase accuracy) against pathologies (like oscillations)– You may want to enforce some other property on the form of the

interpolant● We'll follow the discussion from Pang

Page 15: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Interpolation vs Fitting● Interpolation seeks to fill in missing information in some small region

of the whole dataset● Fitting a function to the data seeks to produce a model (guided by

physical intuition) so you can learn more about the global behavior of your data

Page 16: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Linear Interpolation● Simplest idea—draw a line between two points

– Exactly recovers the function values at the end points

Page 17: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Linear Interpolation● Actual f(x) is given by

– Want to know the error at a point x = a in [xi,xi+1] – We can fit a quadratic to xi, a, xi+1 – Error can be shown (through lots of algebra...) to be

(at that point)● This means error in linear interpolation ∼ O(Δx2)

Linear interpolant

Page 18: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Linear Interpolation● Error estimate graphically

Page 19: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Quadratic Interpolation● Fit a parabola—requires 3 points

– Already saw this with Simpson's rule● Note: can fall out of the range of f1, f2, or f3

– Over/undershoots can be problematic depending on the application

Page 20: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Example: Mass Fractions● Higher-order is not always better.● Practical example

– In hydrodynamics codes, you often carry around mass fractions, Xk with

– If you have these defined at two points: a and b and need them in-between, then:

sums to 1 for all x – Higher-order interpolation can violate this constraint

Page 21: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation● General method for building a single polynomial that goes through

all the points (alternate formulations exist)● Given n points: x0, x1, ... , xn-1, with associated function values: f0, f1, ... ,

fn-1

– construct basis functions:

● Basis function li is 0 at all xj except for xi (where it is 1)– Function value at x is:

Page 22: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation● Consider a quadratic

– Three points:– Three basis functions:

Page 23: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation● Quadratic Lagrange polynomial:

Let's look at the code

Page 24: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation● Form is easy to remember● Not the most efficient form to compute the polynomial

– All other forms for n-degree polynomials that pass through the specified n+1 points are equivalent

– High-order polynomials can suffer from round-off error

Page 25: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Page 26: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Page 27: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Page 28: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Page 29: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Page 30: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Page 31: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Page 32: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Page 33: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Page 34: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation● Notice that, after a bit, increasing the number of interpolating points

increases the error– This is an example of the Runge phenomena (see, e.g., Wikipedia for a discussion +

refs)

● Oscillation becomes pronounced at the end of the interval with polynomial interpolation

● Increasing the number of points causes a divergence of the error (it is getting bigger and bigger)

● We can do better by using variable spacing of the interpolating points– e.g., Chebyshev polynomial roots are concentrated toward the end of

the interval– Chebyshev polynomial spacing is usually (almost always) convergent with

the number of interpolating points● See Six Myths of Polynomial Interpolation and Quadrature by L. N. Trefethen

Page 35: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Interpolating points are Chebyshev nodes

Page 36: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Interpolating points are Chebyshev nodes

Page 37: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Interpolating points are Chebyshev nodes

Page 38: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Interpolating points are Chebyshev nodes

Page 39: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Interpolating points are Chebyshev nodes

Page 40: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Interpolating points are Chebyshev nodes

Page 41: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Interpolating points are Chebyshev nodes

Page 42: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Interpolating points are Chebyshev nodes

Page 43: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Lagrange Interpolation

Interpolating points are Chebyshev nodes

Page 44: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Example: Thermodynamic Consistency● Stellar equations of state (EOS) can be expensive to evaluate

– Solution: tabulate the results in terms of ρ, T, and some (maybe) composition

– Interpolate to find p, e, … everywhere in the ρ – T plane● Problem: what about thermodynamic consistency?

– Solution: interpolate a free energy, and derive needed thermodynamic quantities by differentiating the interpolant itself

● This is the approach of the popular helmeos by Timmes & Swesty (2000)– interpolate Helmholtz free energy:– via first law:

Page 45: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Example: Thermodynamic Consistency● Thermodynamic consistency guaranteed● Now: choice of interpolating function determines accuracy

– Desire for smoothness of derivatives and second derivatives require higher-order polynomial

– Biquintic Herminte polynomial gives smoothness, exactly reproduces first and second partial derivates at grid points

● requires storing F and eight partial derivatives at each point

Page 46: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Conservative Interpolation● Imagine that instead of having f(x) at discrete points, we instead

knew the average of f in some interval– Finite-volume discretization

● We want a interpolant that respects these averages– Conservative interpolant

Page 47: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Conservative Interpolation● Quadratic interpolation

– We are given the average of f in each zone– Constraints:

– Reconstruction polynomial

– Three equations and three unknowns

Page 48: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Conservative Interpolation● Solve for unknowns:

– This recovers the proper averages in each interval– Usually termed reconstruction– We'll see this when we talk about finite-volume methods for advection.

Page 49: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Splines● So far, we've only worried about going through the specified points● Large number of points → two distinct options:

– Use a single high-order polynomial that passes through them all– Fit a (somewhat) high order polynomial to each interval and match all

derivatives at each point—this is a spline● Splines match the derivatives at end points of intervals

– Piecewise splines can give a high-degree of accuracy● Cubic spline is the most popular

– Matches first and second derivative at each data point– Results in a smooth appearance– Avoids severe oscillations of higher-order polynomial

Page 50: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Splines● We have a set of discrete data: fi = f(xi) at x0, x1, x2, ... , xn

– We'll assume regular spacing here

● m-th order polynomial in [xi, xi+1]

● Smoothness requirement: all derivatives match at endpoints

Page 51: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Splines● There are n intervals ([0,1], [1,2], … [n-1,n]) and in each interval,

there are m+1 coefficients for the polynomial– We have (m+1) n total coefficients

● Smoothness operates on the n - 1 interior points● End point values provide 2 more constraints● Remaining constraints come from imposing conditions on the

second derivatives at end points● You are solving for the coefficients of all piecewise polynomial

interpolants together, in a coupled fashion.

Page 52: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Splines Example● Here are 3 intervals / 4 points fit with 3 cubic splines

– Cubic: m = 3– Intervals (# of cubics): n = 3– We need (m+1)n = 12 constraints

● Interior points– At 1:

– At 2:

Page 53: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Splines Example● At the boundaries:

– We need 2 more constraints● Natural boundary conditions—

set the second derivative to 0 at the ends

● Other choices are possible● We now have all the constraints

necessary to solve for the set of cubic splines

Page 54: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Cubic Splines● Cubic splines: 3rd order polynomial in [xi, xi+1]

– 1. Start by linearly interpolating second derivatives

– 2. Integrate twice:

(note we wrote the integration constants in a convenient form)– 3. Impose constraints:

Note: different texts use different forms of the cubic—the ideas are all the same though. This form also seems to be what NR chooses.

Page 55: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Cubic Splines● Result (after a bunch of algebra):

● Note that all the coefficients in the cubic are in terms of the second derivative at the data points. – We need to solve for all second derivatives

● Final continuity constraint:

Page 56: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Cubic Splines● After lots of algebra, we arrive at:

– This is a linear system

– Applies to all interior points, i = 1, ... , ni-1 to give – Natural boundary conditions:

This is our first example of a linear system—we'll see that these pop up all over the place.

Page 57: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Cubic Splines● Matrix form:

– This is a tridiagonal matrix– We'll look at linear algebra later—for now we can use a “canned” solver– Example code...

Page 58: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Cubic Splines

Page 59: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Cubic Splines

Note that the splines can overshoot the original data values

Page 60: Rootsbender.astro.sunysb.edu/.../interpolation-roots.pdf · Cubic Splines Cubic splines: 3rd order polynomial in [x i, xi+1] – 1. Start by linearly interpolating second derivatives

PHY 688: Numerical Methods for (Astro)Physics

Cubic Splines● Note: cubic splines are not necessarily the most accurate

interpolation scheme (and sometimes far from...)● But, for plotting/graphics applications, they look right