NivaarExam PrepOfficial exam papers ↗

04-BS-5 · May 2014

Question 4 of 7: Least-Squares Curve Fitting and an Interpolating Polynomial

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

National Exams — May 2014 — 04-BS-5 Advanced Mathematics. Three-hour, closed-book exam (one double-sided 8.5"×11" aid sheet permitted; approved Casio/Sharp calculator allowed). Format: seven questions of equal value (20 marks each, with internal splits as marked); any five constitute a complete paper and only the first five appearing in the answer book are marked. All seven are solved below for completeness.

Reference texts: Kreyszig, Advanced Engineering Mathematics (10th ed., Wiley) — Sturm–Liouville eigenproblems, Fourier series and the Fourier transform (Ch. 11), least-squares curve fitting, Lagrange/Newton interpolation, Romberg integration, and root-finding by bisection/Newton/fixed-point iteration (Ch. 19), Cholesky factorization (Ch. 20); Strang, Introduction to Linear Algebra (6th ed., Wellesley-Cambridge) — symmetric positive-definite systems and Cholesky factorization.

Question 4: Least-Squares Curve Fitting and an Interpolating Polynomial (10+10 marks)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Given (A). $n$ experimental points $(x_i,y_i)$, $i=1,\dots,n$, to be fit in the least-squares sense by $y=a/x+b/x^3$.

Find (A). Show the least-squares coefficients are $a=D_1/D_S$, $b=D_2/D_S$ with $D_1,D_2,D_S$ as stated.

Approach (A). Minimize the sum of squared residuals $S=\sum(y_i-a/x_i-b/x_i^3)^2$ by setting $\partial S/\partial a=\partial S/\partial b=0$ (the normal equations), then solve the resulting $2\times2$ linear system by Cramer's rule.

  1. Differentiate the objective. $$S=\sum_{i=1}^n\Big(y_i-\frac{a}{x_i}-\frac{b}{x_i^3}\Big)^2,\qquad \frac{\partial S}{\partial a}=-2\sum\frac1{x_i}\Big(y_i-\frac a{x_i}-\frac b{x_i^3}\Big)=0,\qquad \frac{\partial S}{\partial b}=-2\sum\frac1{x_i^3}\Big(y_i-\frac a{x_i}-\frac b{x_i^3}\Big)=0$$
  2. Write the normal equations. $$a\sum\frac1{x_i^2}+b\sum\frac1{x_i^4}=\sum\frac{y_i}{x_i},\qquad a\sum\frac1{x_i^4}+b\sum\frac1{x_i^6}=\sum\frac{y_i}{x_i^3}$$
  3. Solve the $2\times2$ system by Cramer's rule. The coefficient determinant is $$D_S=\sum\frac1{x_i^2}\sum\frac1{x_i^6}-\Big(\sum\frac1{x_i^4}\Big)^2,$$ and replacing the $a$-column, then the $b$-column, of the coefficient matrix with the right-hand side gives $$D_1=\sum\frac{y_i}{x_i}\sum\frac1{x_i^6}-\sum\frac{y_i}{x_i^3}\sum\frac1{x_i^4},\qquad D_2=\sum\frac{y_i}{x_i^3}\sum\frac1{x_i^2}-\sum\frac{y_i}{x_i}\sum\frac1{x_i^4}$$ $$\boxed{a=\dfrac{D_1}{D_S},\qquad b=\dfrac{D_2}{D_S}}$$ which is exactly Cramer's rule applied to the normal equations of Step 2 — the stated result.
Check: the source labels part (B) a "Legendre polynomial." Legendre polynomials are a fixed orthogonal family unrelated to fitting an arbitrary point set; the technique that exactly reproduces four given points with a cubic is polynomial interpolation (Lagrange/Newton form). Solved as an interpolating-polynomial problem below, which is almost certainly the intended technique.

Given (B). Four points: $(-1,0),\ (0,-2),\ (1,-4),\ (2,0)$.

Find (B). The (unique) cubic polynomial $p(x)$ passing exactly through all four points.

Interpolating cubic through the 4 points (official Q4B)-1.5-1-0.500.511.522.5-5-3.8-2.6-1.4-0.21xF(x)
The interpolating cubic through the four given points (markers).

Approach (B). Four points determine a unique cubic; build it efficiently with Newton's divided-difference table, then expand to standard form.

  1. Build the divided-difference table. With nodes $x_0,\dots,x_3=-1,0,1,2$ and $y_0,\dots,y_3=0,-2,-4,0$: $$f[x_0,x_1]=\frac{-2-0}{0-(-1)}=-2,\quad f[x_1,x_2]=\frac{-4-(-2)}{1-0}=-2,\quad f[x_2,x_3]=\frac{0-(-4)}{2-1}=4$$ $$f[x_0,x_1,x_2]=\frac{-2-(-2)}{1-(-1)}=0,\quad f[x_1,x_2,x_3]=\frac{4-(-2)}{2-0}=3$$ $$f[x_0,x_1,x_2,x_3]=\frac{3-0}{2-(-1)}=1$$
  2. Assemble Newton's form and expand. $$p(x)=f[x_0]+f[x_0,x_1](x-x_0)+f[x_0,x_1,x_2](x-x_0)(x-x_1)+f[x_0,x_1,x_2,x_3](x-x_0)(x-x_1)(x-x_2)$$ $$p(x)=0-2(x+1)+0\cdot(x+1)x+1\cdot(x+1)x(x-1)=-2x-2+x(x^2-1)$$ $$\boxed{p(x)=x^3-3x-2}$$
  3. Verify at all four nodes. $p(-1)=-1+3-2=0$; $p(0)=-2$; $p(1)=1-3-2=-4$; $p(2)=8-6-2=0$ — all four match the given data exactly, confirming the fit.
Least-squares proof and the interpolating cubic
PartResult
(A)a = D1/DS,  b = D2/DS (Cramer's rule on the normal equations)
(B)p(x) = x³ − 3x − 2