Computational Physics PHYS 420
Dr Richard H. Cyburt Assistant Professor of Physics My office: 402c in the Science Building My phone: (304) 384-6006 My email: rcyburt@concord.edu My webpage: www.concord.edu/rcyburt In person or email is the best way to get a hold of me.
My Office Hours TR: 9:30-11:00, 13:00-15:00 F: 9:00-11:00, 13:00-15:00 Meetings may also be arranged at other times, by appointment
Midterm approaches nigh Tuesday, Oct 3 during class PHYS420
Computational Physics
Douglas Adams Hitchhiker s Guide to the Galaxy
Interpolation and Splines n Basis: In Linear Algebra, a basis is a set of vectors satisfying: Ø Linear combination of the basis can represent every vector in a given vector space; Ø No element of the set can be represented as a linear combination of the others.
n In Function Space, Basis is degenerated to a set of basis functions; n Each function in the function space can be represented as a linear combination of the basis functions. n Example: Quadratic Polynomial bases {1,t,t 2 }
n n n What are basis functions? We need flexible method for constructing a function f(t), can be as simple or complex as we want/need. We pick a system of K basis functions φ k (t), and call this the basis for f(t). We express f(t) as a weighted sum of these basis functions: f(t) = a 1 φ 1 (t) + a 2 φ 2 (t) + + a K φ K (t) The coefficients a 1,, a K determine the shape of the function.
n n n n n What do we want from basis functions? Fast computation of individual basis functions. Flexible: can exhibit the required curvature where needed, but also be nearly linear when appropriate. Fast computation of coefficients a k : possible if matrices of values are diagonal, banded or sparse. Differentiable as required: We make lots of use of derivatives in functional data analysis. Constrained as required, such as periodicity, positivity, monotonicity, asymptotes and etc.
n What are some commonly used basis functions? Powers: 1, t, t 2, and so on. They are the basis functions for polynomials. These are not very flexible, and are used only for simple problems. n Fourier series: 1, sin(ωt), cos(ωt), sin(2ωt), cos(2ωt), and so on for a fixed known frequency ω. These are used for periodic functions. n Spline functions: These have now more or less replaced polynomials for non-periodic problems. More explanation follows.
What is Basis Expansion? n Given data X and basis functions, h ( ) m X Then we can model + f X = % β ' h ' (X) ',- as a linear basis expansion in X, where is a basis function. hm ( X )
Why Basis Expansion? n In regression problems, f(x) will typically nonlinear in X; n Linear model is convenient and easy to interpret;
n Spline: 2. Piecewise Polynomials and Splines Ø In Mathematics, a spline is a special function defined piecewise by polynomials; Ø In Computer Science, the term spline more frequently refers to a piecewise polynomial (parametric) curve. n Simple construction, ease and accuracy of evaluation, capacity to approximate complex shapes through curve fitting and interactive curve design.
n Assume a four knots spline (two boundary knots and two interior knots), also X is one dimensional.
n Assume four knots spline (two boundary knots and two interior knots), also X is one dimensional. n Piecewise constant basis: h - X = 1 for X < ξ -, h 6 X = 1 for ξ - < X < ξ 6, h 7 X = 1 for X > ξ 6 n Piecewise Linear Basis: h - X = X for X < ξ -, h 6 X = X ξ - for ξ - < X < ξ 6, h 7 X = X ξ 6 for X > ξ 6
Piecewise Cubic Polynomial
Spline Interpolation Method
What is Interpolation? Given (x 0,y 0 ), (x 1,y 1 ), (x n,y n ), find the value of y at a value of x that is not given.
Interpolants Polynomials are the most common choice of interpolants because they are easy to: Evaluate Differentiate, and Integrate.
Why Splines? f(x) = Table : Six equidistantly spaced points in [-1, 1] 1 y = 1+ 25x x 2-1.0 0.038461-0.6 0.1-0.2 0.5 0.2 0.5 1 1 + 25x 6 0.6 0.1 1.0 0.038461 Figure : 5 th order polynomial vs. exact function 24
Why Splines? 1.2 0.8 0.4 y 0-1 -0.5 0 0.5 1-0.4-0.8 x 19th Order Polynomial f (x) 5th Order Polynomial Figure : Higher order polynomial interpolation is a bad idea
Spline Interpolation l Linear, Quadratic, Cubic l Preferred over other polynomial interpolation l More efficient l High-degree polynomials are very computationally expensive l Smaller error l Interpolant is smoother
Spline Interpolation Definition l Given n+1 distinct knots x i such that: with n+1 knot values y i find a spline function with each S i (x) a polynomial of degree at most n.
Linear Spline Interpolation l Simplest form of spline interpolation l Points connected by lines Each S i is a linear function constructed as: Must be continuous at each data point: Continuity:
Quadratic Spline Interpolation l The quadratic spline can be constructed as: The coefficients can be found by choosing a z 0 and then using the recurrence relation:
Quadratic Splines 2 l Quadratic splines are rarely used for interpolation for practical purposes l Ideally quadratic splines are only used to understand cubic splines
Quadratic Spline Graph Dx=2
Quadratic Spline Graph Dx=0.5
Natural Cubic Spline Interpolation SPLINE OF DEGREE k = 3 l The domain of S is an interval [a,b]. l S, S, S are all continuous functions on [a,b]. l There are points t i (the knots of S) such that a = t 0 < t 1 < < t n = b and such that S is a polynomial of degree at most k on each subinterval [t i, t i+1 ]. x t 0 t 1 t n y y 0 y 1 y n t i are knots
Natural Cubic Spline Interpolation S i (x) is a cubic polynomial that will be used on the subinterval [ x i, x i+1 ].
Natural Cubic Spline Interpolation l S i (x) = a i x 3 + b i x 2 + c i x + d i l 4 Coefficients with n subintervals = 4n equations l There are 4n-2 conditions l Interpolation conditions l Continuity conditions l Natural Conditions l S (x 0 ) = 0 l S (x n ) = 0
Hand spline interpolation
Bezier Spline Interpolation l A similar but different problem: Controlling the shape of curves. Problem: given some (control) points, produce and modify the shape of a curve passing through the first and last point. http://www.ibiblio.org/e-notes/splines/bezier.htm
Bezier Spline Interpolation Practical Application
Bezier Spline Interpolation Idea: Build functions that are combinations of some basic and simpler functions. Basic functions: B-splines Bernstein polynomials
Bernstein Polynomials l Bernstein polynomials of degree N are defined by: l For n = 0, 1, 2,, n, where = <! >! <?>! l In general there are N+1 Bernstein Polynomials of degree N. For example, the Bernstein Polynomials of degrees 1, 2, and 3 are: l 1. B 0,1 (t) = 1-t, B 1,1 (t) = t; l 2. B 0,2 (t) = (1-t) 2, B 1,2 (t) = 2t(1-t), B 2,2 (t) = t 2 ; l 3. B 0,3 (t) = (1-t) 3, B 1,3 (t) = 3t(1-t) 2, B 2,3 (t)=3t 2 (1-t), B 3,3 (t) = t 3 ;