Gaussian elimination, LU decompositions, and errors LS solving Problem 1 [8 points] Consider the system A x = b Ax = b A x = b , where
A = [ 0.1 0.3 0.9 0.3 0.9 2.7 0.6 0.7 0.1 ] A=\begin{bmatrix} 0.1 & 0.3 & 0.9\\ 0.3 & 0.9 & 2.7\\ 0.6 & 0.7 & 0.1 \end{bmatrix} A = 0.1 0.3 0.6 0.3 0.9 0.7 0.9 2.7 0.1
and b = [ 1.3 3.9 1.4 ] T b = \begin{bmatrix} 1.3 & 3.9 & 1.4\end{bmatrix}^T b = [ 1.3 3.9 1.4 ] T
a. [2 points] Show that A A A is singular.
b. [2 points] If we were to use Gaussian elimination with partial pivoting to solve this system using exact arithmetic, show where the process fails.
c. [2 points] Solve this system in double precision using partial pivoting. Do not use Matlab’s functions. What is the solution that you obtain?
d. [2 points] Matlab’s A\b
produces NaN -Inf Inf
as a solution. Explain why NaN, -Inf and Inf.
Answer :
a. For A A A to be singular, prove d e t ( A ) = 0 det(A) = 0 d e t ( A ) = 0
Using Gaussian elimination without partial pivoting
A ∣ b = [ 0.1 0.3 0.9 ∣ 1.3 0.3 0.9 2.7 ∣ 3.9 0.6 0.7 0.1 ∣ 1.4 ] R 2 − R 1 → A ∣ b = [ 0.1 0.3 0.9 ∣ 1.3 0.2 0.6 1.8 ∣ 2.6 0.6 0.7 0.1 ∣ 1.4 ] R 3 − 3 ∗ R 1 → A ∣ b = [ 0.1 0.3 0.9 ∣ 1.3 0.2 0.6 1.8 ∣ 2.6 0.3 − 0.2 − 2.6 ∣ − 2.5 ] R 3 − 1 2 ∗ R 2 → A ∣ b = [ 0.1 0.3 0.9 ∣ 1.3 0.2 0.6 1.8 ∣ 2.6 0.2 − 0.5 − 3.5 ∣ − 3.8 ] Thus → A ∣ b ← [ 0.1 0.3 0.9 ∣ 1.3 0.2 0.6 1.8 ∣ 2.6 0.2 − 0.5 − 3.5 ∣ − 3.8 ] d e t ( A ) = a ( e i − f h ) − b ( d i − f g ) + c ( d h − e g ) , A = [ a b c d e f g h i ] → d e t ( A ) = 0.1 ∗ ( − 0.6 ∗ 3.5 + 1.8 ∗ 0.5 ) − 0.3 ∗ ( − 0.2 ∗ 3.5 − 1.8 ∗ 0.2 ) + 0.9 ∗ ( − 0.5 ∗ 0.2 − 0.6 ∗ 0.2 ) = 0 \begin{aligned}
A|b &= \begin{bmatrix} 0.1 & 0.3 & 0.9 & | & 1.3\\ 0.3 & 0.9 & 2.7 & | & 3.9\\ 0.6 & 0.7 & 0.1 & | & 1.4 \end{bmatrix} \\\
R_{2} - R_{1} \rightarrow A|b &= \begin{bmatrix} 0.1 & 0.3 & 0.9 & | & 1.3\\ 0.2 & 0.6 & 1.8 & | & 2.6\\ 0.6 & 0.7 & 0.1 & | & 1.4 \end{bmatrix} \\\
R_{3} - 3*R_{1} \rightarrow A|b &= \begin{bmatrix} 0.1 & 0.3 & 0.9 & | & 1.3\\ 0.2 & 0.6 & 1.8 & | & 2.6\\ 0.3 & -0.2 & -2.6 & | & -2.5 \end{bmatrix} \\\
R_3 - \frac{1}{2}*R_2 \rightarrow A|b &= \begin{bmatrix} 0.1 & 0.3 & 0.9 & | & 1.3\\ 0.2 & 0.6 & 1.8 & | & 2.6\\ 0.2 & -0.5 & -3.5 & | & -3.8 \end{bmatrix} \\\
\text{Thus } \rightarrow A|b \leftarrow &\begin{bmatrix} 0.1 & 0.3 & 0.9 & | & 1.3\\ 0.2 & 0.6 & 1.8 & | & 2.6\\ 0.2 & -0.5 & -3.5 & | & -3.8 \end{bmatrix} \\\
& \\\
det(A) = a(ei−fh)−b(di−fg)+c(dh−eg), A &=\begin{bmatrix} a & b & c \\ d & e & f\\ g & h & i \end{bmatrix} \\\
& \\\
\rightarrow det(A) = 0.1*(-0.6*3.5+1.8*0.5) - & \\\
0.3*(-0.2*3.5-1.8*0.2) + & \\\
0.9*(-0.5*0.2-0.6*0.2) &= 0
\end{aligned} A ∣ b R 2 − R 1 → A ∣ b R 3 − 3 ∗ R 1 → A ∣ b R 3 − 2 1 ∗ R 2 → A ∣ b Thus → A ∣ b ← d e t ( A ) = a ( e i − f h ) − b ( d i − f g ) + c ( d h − e g ) , A → d e t ( A ) = 0.1 ∗ ( − 0.6 ∗ 3.5 + 1.8 ∗ 0.5 ) − 0.3 ∗ ( − 0.2 ∗ 3.5 − 1.8 ∗ 0.2 ) + 0.9 ∗ ( − 0.5 ∗ 0.2 − 0.6 ∗ 0.2 ) = 0.1 0.3 0.6 0.3 0.9 0.7 0.9 2.7 0.1 ∣ ∣ ∣ 1.3 3.9 1.4 = 0.1 0.2 0.6 0.3 0.6 0.7 0.9 1.8 0.1 ∣ ∣ ∣ 1.3 2.6 1.4 = 0.1 0.2 0.3 0.3 0.6 − 0.2 0.9 1.8 − 2.6 ∣ ∣ ∣ 1.3 2.6 − 2.5 = 0.1 0.2 0.2 0.3 0.6 − 0.5 0.9 1.8 − 3.5 ∣ ∣ ∣ 1.3 2.6 − 3.8 0.1 0.2 0.2 0.3 0.6 − 0.5 0.9 1.8 − 3.5 ∣ ∣ ∣ 1.3 2.6 − 3.8 = a d g b e h c f i = 0
b. With partial pivoting :
A ∣ b = [ 0.1 0.3 0.9 ∣ 1.3 0.3 0.9 2.7 ∣ 3.9 0.6 0.7 0.1 ∣ 1.4 ] R 3 ↔ R 1 ← A ∣ b = [ 0.6 0.7 0.1 ∣ 1.4 0.3 0.9 2.7 ∣ 3.9 0.1 0.3 0.9 ∣ 1.3 ] R 2 − 1 2 R 1 ← A ∣ b = [ 0.6 0.7 0.1 ∣ 1.4 0 0.55 2.65 ∣ 3.2 0.1 0.3 0.9 ∣ 1.3 ] R 3 − 1 6 R 1 ← A ∣ b = [ 0.6 0.7 0.1 ∣ 1.4 0 0.55 2.65 ∣ 3.2 0 0.18333333 0.88333333 ∣ 1.06666667 ] R 3 − 1 3 R 2 ← A ∣ b = [ 0.6 0.7 0.1 ∣ 1.4 0 0.55 2.65 ∣ 3.2 0 0 0 ∣ − 0.3 ] \begin{align}
A|b &=\begin{bmatrix} 0.1 & 0.3 & 0.9 & | & 1.3\\ 0.3 & 0.9 & 2.7 & | & 3.9\\ 0.6 & 0.7 & 0.1 & | & 1.4 \end{bmatrix} \\\
R3 \leftrightarrow R1 \leftarrow A|b&=\begin{bmatrix} 0.6 & 0.7 & 0.1 & | & 1.4\\ 0.3 & 0.9 & 2.7 & | & 3.9\\ 0.1 & 0.3 & 0.9 & | & 1.3 \end{bmatrix} \\\
R2 - \frac{1}{2}R1 \leftarrow A|b&=\begin{bmatrix} 0.6 & 0.7 & 0.1 & | & 1.4\\ 0 & 0.55 & 2.65 & | & 3.2\\ 0.1 & 0.3 & 0.9 & | & 1.3 \end{bmatrix} \\\
R3 - \frac{1}{6}R1 \leftarrow A|b&=\begin{bmatrix} 0.6 & 0.7 & 0.1 & | & 1.4\\ 0 & 0.55 & 2.65 & | & 3.2\\ 0 & 0.18333333 & 0.88333333 & | & 1.06666667 \end{bmatrix} \\\
R3 - \frac{1}{3}R2 \leftarrow A|b&=\begin{bmatrix} 0.6 & 0.7 & 0.1 & | & 1.4\\ 0 & 0.55 & 2.65 & | & 3.2\\ 0 & 0 & 0 & | & -0.3 \end{bmatrix}
\end{align} A ∣ b R 3 ↔ R 1 ← A ∣ b R 2 − 2 1 R 1 ← A ∣ b R 3 − 6 1 R 1 ← A ∣ b R 3 − 3 1 R 2 ← A ∣ b = 0.1 0.3 0.6 0.3 0.9 0.7 0.9 2.7 0.1 ∣ ∣ ∣ 1.3 3.9 1.4 = 0.6 0.3 0.1 0.7 0.9 0.3 0.1 2.7 0.9 ∣ ∣ ∣ 1.4 3.9 1.3 = 0.6 0 0.1 0.7 0.55 0.3 0.1 2.65 0.9 ∣ ∣ ∣ 1.4 3.2 1.3 = 0.6 0 0 0.7 0.55 0.18333333 0.1 2.65 0.88333333 ∣ ∣ ∣ 1.4 3.2 1.06666667 = 0.6 0 0 0.7 0.55 0 0.1 2.65 0 ∣ ∣ ∣ 1.4 3.2 − 0.3
We notice that R 3 − 1 3 R 2 → 0 = − 0.3 R3-\frac{1}{3}R2 \rightarrow 0=-0.3 R 3 − 3 1 R 2 → 0 = − 0.3 , thus invalid.
c. With partial pivoting in double precision
The L U LU LU decomposition of A = [ 0.1 0.3 0.9 0.3 0.9 2.7 0.6 0.7 0.1 ] A=\begin{bmatrix} 0.1 & 0.3 & 0.9\\ 0.3 & 0.9 & 2.7\\ 0.6 & 0.7 & 0.1 \end{bmatrix} A = 0.1 0.3 0.6 0.3 0.9 0.7 0.9 2.7 0.1
The following portray steps to calculate U U U (lower triangular) :
R 3 ↔ R 1 → U = [ 0.6 0.7 0.1 0.3 0.9 2.7 0.1 0.3 0.9 ] , P 1 = [ 0 0 1 0 1 0 1 0 0 ] R 2 − 1 2 R 1 → U = [ 0.6 0.7 0.1 0 0.55 2.6500000000000004 0.1 0.3 0.9 ] R 3 − 1 6 R 1 → U = [ 0.6 0.7 0.1 0 0.55 2.6500000000000004 0 0.18333333333333335 0.8833333333333333 ] R 3 − 1 3 R 2 → U = [ 0.6 0.7 0.1 0 0.55 2.6500000000000004 0 0 4.8109664400423476 × 10 − 17 ] \begin{aligned}
R_3 \leftrightarrow R_1 \rightarrow U &= \begin{bmatrix} 0.6 & 0.7 & 0.1\\ 0.3 & 0.9 & 2.7\\ 0.1 & 0.3 & 0.9 \end{bmatrix}, \quad P_1 = \begin{bmatrix} 0 & 0 & 1\\ 0 & 1 & 0\\ 1 & 0 & 0 \end{bmatrix} \\\
R_2 - \frac{1}{2}R_1 \rightarrow U &= \begin{bmatrix} 0.6 & 0.7 & 0.1\\ 0 & 0.55 & 2.6500000000000004\\ 0.1 & 0.3 & 0.9 \end{bmatrix} \\\
R_3 - \frac{1}{6}R_1 \rightarrow U &= \begin{bmatrix} 0.6 & 0.7 & 0.1\\ 0 & 0.55 & 2.6500000000000004\\ 0 & 0.18333333333333335 & 0.8833333333333333 \end{bmatrix} \\\
R_3 - \frac{1}{3}R_2 \rightarrow U &= \begin{bmatrix} 0.6 & 0.7 & 0.1\\ 0 & 0.55 & 2.6500000000000004\\ 0 & 0 & 4.8109664400423476 \times 10^{-17} \end{bmatrix}
\end{aligned} R 3 ↔ R 1 → U R 2 − 2 1 R 1 → U R 3 − 6 1 R 1 → U R 3 − 3 1 R 2 → U = 0.6 0.3 0.1 0.7 0.9 0.3 0.1 2.7 0.9 , P 1 = 0 0 1 0 1 0 1 0 0 = 0.6 0 0.1 0.7 0.55 0.3 0.1 2.6500000000000004 0.9 = 0.6 0 0 0.7 0.55 0.18333333333333335 0.1 2.6500000000000004 0.8833333333333333 = 0.6 0 0 0.7 0.55 0 0.1 2.6500000000000004 4.8109664400423476 × 1 0 − 17
_note: the a 33 a_{33} a 33 is close to zero, hence consistent with previous finding_
L = [ 1 0 0 0.5 1 0 0.16666666666666669 0.33333333333333326 1 ] L=\begin{bmatrix} 1 & 0 & 0\\ 0.5 & 1 & 0\\ 0.16666666666666669 & 0.33333333333333326 & 1 \end{bmatrix} L = 1 0.5 0.16666666666666669 0 1 0.33333333333333326 0 0 1
To solve for x x x with L U LU LU decomposition, We solve L ( U x ) = P b L(Ux)=Pb L ( Ux ) = P b
→ x = [ 14.006993006993 − 10.48951048951048 3.3846153846153832 ] \rightarrow x=\begin{bmatrix} 14.006993006993 & -10.48951048951048 & 3.3846153846153832\end{bmatrix} → x = [ 14.006993006993 − 10.48951048951048 3.3846153846153832 ]
d. Since A is singular, it doesn’t have an inverse.
Matlab uses LU decomposition, and as we explored above, a pivot element is found to be zero or close to zero (matrix is probably ill-conditioned ), which leads to 0 x 1 + 0 x 2 + 0 x 3 = non negative value 0x_1 + 0x_2 + 0x_3=\text{non negative value} 0 x 1 + 0 x 2 + 0 x 3 = non negative value , which results in NaN
. For the second value -Inf
, the division is small. Inf
is due to division by zero
Problem 2 [2 points] Apply Gaussian elimination with partial pivoting on the following matrix A = [ 1 0 0 0 1 − 1 1 0 0 1 − 1 − 1 1 0 1 − 1 − 1 − 1 1 1 − 1 − 1 − 1 − 1 1 ] A=\begin{bmatrix} 1 & 0 & 0 & 0 & 1\\ −1 & 1 & 0 & 0 & 1\\ −1 & −1 & 1 & 0 & 1\\ −1 & −1 & −1 & 1 & 1\\ −1 & −1 & −1 & −1 & 1 \end{bmatrix} A = 1 − 1 − 1 − 1 − 1 0 1 − 1 − 1 − 1 0 0 1 − 1 − 1 0 0 0 1 − 1 1 1 1 1 1
Show all the steps.
Answer :
A = [ 1 0 0 0 1 − 1 1 0 0 1 − 1 − 1 1 0 1 − 1 − 1 − 1 1 1 − 1 − 1 − 1 − 1 1 ] A=\begin{bmatrix} 1 & 0 & 0 & 0 & 1\\ −1 & 1 & 0 & 0 & 1\\ −1 & −1 & 1 & 0 & 1\\ −1 & −1 & −1 & 1 & 1\\ −1 & −1 & −1 & −1 & 1 \end{bmatrix} A = 1 − 1 − 1 − 1 − 1 0 1 − 1 − 1 − 1 0 0 1 − 1 − 1 0 0 0 1 − 1 1 1 1 1 1
R 2 + R 1 and R 3 + R 1 and R 4 + R 1 and R 5 + R 1 → A = [ 1 0 0 0 1 0 1 0 0 2 0 − 1 1 0 2 0 − 1 − 1 1 2 0 − 1 − 1 − 1 2 ] R2+R1 \text{ and } R3+R1\text{ and } R4+R1\text{ and } R5+R1\rightarrow A=\begin{bmatrix} 1 & 0 & 0 & 0 & 1\\ 0 & 1 & 0 & 0 & 2\\ 0 & −1 & 1 & 0 & 2\\ 0 & −1 & −1 & 1 & 2\\ 0 & −1 & −1 & −1 & 2 \end{bmatrix} R 2 + R 1 and R 3 + R 1 and R 4 + R 1 and R 5 + R 1 → A = 1 0 0 0 0 0 1 − 1 − 1 − 1 0 0 1 − 1 − 1 0 0 0 1 − 1 1 2 2 2 2
R 3 + R 2 and R 4 + R 2 and R 5 + R 2 → A = [ 1 0 0 0 1 0 1 0 0 2 0 0 1 0 4 0 0 − 1 1 4 0 0 − 1 − 1 4 ] R3+R2 \text{ and } R4+R2\text{ and } R5+R2\rightarrow A=\begin{bmatrix} 1 & 0 & 0 & 0 & 1\\ 0 & 1 & 0 & 0 & 2\\ 0 & 0 & 1 & 0 & 4\\ 0 & 0 & −1 & 1 & 4\\ 0 & 0 & −1 & −1 & 4 \end{bmatrix} R 3 + R 2 and R 4 + R 2 and R 5 + R 2 → A = 1 0 0 0 0 0 1 0 0 0 0 0 1 − 1 − 1 0 0 0 1 − 1 1 2 4 4 4
R 4 + R 3 and R 5 + R 3 → A = [ 1 0 0 0 1 0 1 0 0 2 0 0 1 0 4 0 0 0 1 8 0 0 0 − 1 8 ] R4+R3 \text{ and } R5+R3\rightarrow A=\begin{bmatrix} 1 & 0 & 0 & 0 & 1\\ 0 & 1 & 0 & 0 & 2\\ 0 & 0 & 1 & 0 & 4\\ 0 & 0 & 0 & 1 & 8\\ 0 & 0 & 0 & −1 & 8 \end{bmatrix} R 4 + R 3 and R 5 + R 3 → A = 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 − 1 1 2 4 8 8
R 5 + R 4 → A = [ 1 0 0 0 1 0 1 0 0 2 0 0 1 0 4 0 0 0 1 8 0 0 0 0 16 ] R5+R4\rightarrow A=\begin{bmatrix} 1 & 0 & 0 & 0 & 1\\ 0 & 1 & 0 & 0 & 2\\ 0 & 0 & 1 & 0 & 4\\ 0 & 0 & 0 & 1 & 8\\ 0 & 0 & 0 & 0 & 16 \end{bmatrix} R 5 + R 4 → A = 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 2 4 8 16
Problem 3 [5 points]
(a) (3 points) Let A A A , B B B , and C C C be n × n n × n n × n matrices, where B B B and C C C are nonsingular. For an n − n- n − vector b b b , describe how you would implement the formula x = C − 1 ( A + I ) ( A + B − 1 ) b . x = C^{-1} (A + I)(A + B^{−1})b. x = C − 1 ( A + I ) ( A + B − 1 ) b . without computing any inverses. Here, I I I is the n × n n × n n × n identity matrix.
(b) (2 points) What is the complexity of your approach in terms of big-O notation?
Answer :
a. Given B B B and C C C are non-singular
Step 1: Using L U LU LU decomposition of B, such that B = L U B=LU B = LU
Step 2: Solve for y y y in B y = b By=b B y = b (As y = B − 1 b y=B^{-1}b y = B − 1 b )
solve for z z z in L z = b Lz=b L z = b via forward substitution
solve for y y y in U y = z Uy=z U y = z via backward substitution
Step 3: Compute z = ( A + B − 1 ) b z=(A+B^{-1})b z = ( A + B − 1 ) b
This becomes z = A b + y z=Ab+y z = A b + y
Step 4: Compute w = ( A + I ) z w = (A+I)z w = ( A + I ) z
Via matrix multiplication → w = A z + z \rightarrow w=Az + z → w = A z + z
Step 5: using L U LU LU decomposition of C, such that C = L U C=LU C = LU
Step 6: Solve for x x x in C x = w Cx=w C x = w (As x = C − 1 w x=C^{-1}w x = C − 1 w )
Solve for z ′ z' z ′ in L z ′ = w Lz'=w L z ′ = w via forward substitution
Solve for x x x in U x = z ′ Ux=z' Ux = z ′ via backward substitution
With expansion, solved x = C − 1 ( A + I ) ( A + B − 1 ) b . x = C^{-1} (A + I)(A + B^{−1})b. x = C − 1 ( A + I ) ( A + B − 1 ) b .
b. Complexity analysis
Let total_cost
be the big-O notation
Step 1 using L U LU LU decomposition of B B B
→ total_cost = O ( n 3 ) \rightarrow \text{total\_cost}=O(n^3) → total_cost = O ( n 3 )
Step 2 solving each L z = b Lz=b L z = b and U y = z Uy=z U y = z takes O ( n 2 ) O(n^2) O ( n 2 ) each, thus solving L z = b Lz=b L z = b using L U LU LU decomposition takes O ( 2 n 2 ) O(2n^2) O ( 2 n 2 )
→ total_cost = O ( n 3 ) + O ( 2 n 2 ) \rightarrow \text{total\_cost}=O(n^3) + O(2n^2) → total_cost = O ( n 3 ) + O ( 2 n 2 )
Step 3 Compute z = ( A + B − 1 ) b z=(A+B^{-1})b z = ( A + B − 1 ) b
MatmulOp of A b Ab A b is O ( n 2 ) O(n^2) O ( n 2 )
AddOp of A b + y Ab+y A b + y is O ( n ) O(n) O ( n )
Total for this step O ( n 2 ) + O ( n ) O(n^2) + O(n) O ( n 2 ) + O ( n )
→ total_cost = O ( n 3 ) + O ( 3 n 2 ) + O ( n ) \rightarrow \text{total\_cost}=O(n^3) + O(3n^2) + O(n) → total_cost = O ( n 3 ) + O ( 3 n 2 ) + O ( n )
Step 4 Compute w = ( A + I ) z w = (A+I)z w = ( A + I ) z
MatmulOp of A b Ab A b is O ( n 2 ) O(n^2) O ( n 2 )
AddOp of A b + y Ab+y A b + y is O ( n ) O(n) O ( n )
Total for this step O ( n 2 ) + O ( n ) O(n^2) + O(n) O ( n 2 ) + O ( n )
→ total_cost = O ( n 3 ) + O ( 4 n 2 ) + O ( 2 n ) \rightarrow \text{total\_cost}=O(n^3) + O(4n^2) + O(2n) → total_cost = O ( n 3 ) + O ( 4 n 2 ) + O ( 2 n )
Step 5 using L U LU LU decomposition of C C C
→ total_cost = O ( 2 n 3 ) + O ( 4 n 2 ) + O ( 2 n ) \rightarrow \text{total\_cost}=O(2n^3) + O(4n^2) + O(2n) → total_cost = O ( 2 n 3 ) + O ( 4 n 2 ) + O ( 2 n )
Step 6 solving each L z ′ = w Lz'=w L z ′ = w and U x = z ′ Ux=z' Ux = z ′ using LU composition takes O ( 2 n 2 ) O(2n^2) O ( 2 n 2 )
→ total_cost = O ( 2 n 3 ) + O ( 6 n 2 ) + O ( 2 n ) \rightarrow \text{total\_cost}=O(2n^3) + O(6n^2) + O(2n) → total_cost = O ( 2 n 3 ) + O ( 6 n 2 ) + O ( 2 n )
Problem 4 [6 points] An n × n n × n n × n Hilbert matrix, denote it by H H H , has entries
h i j = 1 ( i + j − 1 ) , i , j = 1 , . . . , n . h_{ij} = \frac{1}{(i+j-1)}, i, j = 1, . . . , n. h ij = ( i + j − 1 ) 1 , i , j = 1 , ... , n .
For n = 2 , 3 , . . . n = 2, 3, . . . n = 2 , 3 , ... , generate the Hilbert matrix of order n n n , and also generate the n − n- n − vector b = H x b = Hx b = H x , where x x x is a random vector. Solve the resulting system H x = b Hx = b H x = b to obtain an
approximate solution x ^ \hat{x} x ^ . (See the functions hilb
and rand
.)
(a) [2 points] How large can you take n n n before the error ∥ x ^ − x ∥ ∥ x ∥ \frac{\Vert{\hat{x} - x}\Vert}{\Vert{x}\Vert} ∥ x ∥ ∥ x ^ − x ∥ is 100 percent?
(b) [2 points] For n n n up to the value you find in (a), report ∥ r ∥ ∥ b ∥ \frac{\Vert{r}\Vert}{\Vert{b}\Vert} ∥ b ∥ ∥ r ∥ , where r = b − H x ^ r = b − H\hat{x} r = b − H x ^ , and ∥ x ^ − x ∥ ∥ x ∥ \frac{\Vert{\hat{x} - x}\Vert}{\Vert{x}\Vert} ∥ x ∥ ∥ x ^ − x ∥ .
(c) [2 points] As n n n increases, how does the number of correct digits in the computed solution relate to the condition number of the matrix?
See the cond
function.
Submit your Matlab program producing the above results. Name the Matlab file hilb_problem.m
.
Answer :
The following hilb_problem.m
is used:
hilb_problem.m function hilb_problem ()
n = 1 ;
while true
% Generate Hilbert matrix of order n
H = hilb(n);
% Generate random vector x
x = rand(n, 1 );
% Compute b = Hx
b = H * x;
% Solve the system Hx = b
x_hat = H \ b;
% Compute the relative error
error = norm(x_hat - x) / norm(x);
fprintf( "error=%d, n=%d\n" , error, n)
% If the error is 100 percent, break
if error >= 1
break ;
end
n = n + 1 ;
end
fprintf( ' \n ============= \n\n The largest n before the error is 100 percent is: %d\n\n ============= \n ' , n- 1 );
for i = 1 :n- 1
H = hilb(i);
x = rand(i, 1 );
b = H * x;
x_hat = H \ b;
r = b - H * x_hat;
rel_resid = norm(r) / norm(b);
rel_error = norm(x_hat - x) / norm(x);
% fprintf('%d %.16f\n',i, rel_resid)
fprintf( '| %d | %.32f | %.32f | \n ' , i, rel_resid, rel_error);
end
cond_num = cond(H);
fprintf( 'The condition number of the matrix for n = %d is: %f\n ' , n- 1 , cond_num);
end
a. largest n = 12 n=12 n = 12 before the error ∥ x ^ − x ∥ ∥ x ∥ \frac{\Vert{\hat{x} - x}\Vert}{\Vert{x}\Vert} ∥ x ∥ ∥ x ^ − x ∥ is 100 percent.
b. The following entails the value of ∥ r ∥ ∥ b ∥ \frac{\Vert{r}\Vert}{\Vert{b}\Vert} ∥ b ∥ ∥ r ∥ and ∥ x ^ − x ∥ ∥ x ∥ \frac{\Vert{\hat{x} - x}\Vert}{\Vert{x}\Vert} ∥ x ∥ ∥ x ^ − x ∥
n ∥ r ∥ ∥ b ∥ \frac{\Vert{r}\Vert}{\Vert{b}\Vert} ∥ b ∥ ∥ r ∥ ∥ x ^ − x ∥ ∥ x ∥ \frac{\Vert{\hat{x} - x}\Vert}{\Vert{x}\Vert} ∥ x ∥ ∥ x ^ − x ∥ 1 0.00000000000000000000000000000000 0.00000000000000000000000000000000 2 0.00000000000000000000000000000000 0.00000000000000013220372219891702 3 0.00000000000000000000000000000000 0.00000000000000363350625815651572 4 0.00000000000000000000000000000000 0.00000000000006709266750580992637 5 0.00000000000000007733975117624287 0.00000000000747821082933078000054 6 0.00000000000000013934207506736382 0.00000000023960543432895825359428 7 0.00000000000000010660570398371085 0.00000000837749558262967895463873 8 0.00000000000000007165565184570407 0.00000009992506975169996005028294 9 0.00000000000000007076549838447114 0.00000608952488692639798140973303 10 0.00000000000000012662840530707719 0.00002450986238666613242472361311 11 0.00000000000000011997633780813789 0.00379971054180424641297242338567 12 0.00000000000000006503338066505365 0.25404291536273732043937911839748
c. As n n n increases, the condition number increases, which means the matrix becomes more ill-conditioned. This means fewer digits in the computed solution are correct.
The number of correct digits in the computed solution decreases due to the increase in the condition number as n n n increases
Problem 5 [4 points] You have to interpolate s i n ( x ) sin(x) s in ( x ) by a polynomial of degree five using equally spaced points in [0, 1].
(a) [2 points] What (absolute) error would you expect if you use this polynomial?
(b) [2 points] Using equally spaced points, what degree polynomial would you use to achieve a maximum error of 10 − 8 10^{-8} 1 0 − 8 ?
Answer :
a. Interpolate s i n ( x ) sin(x) s in ( x ) by a polynomial of degree five using equally spaced on in [ 0 , 1 ] [0,1] [ 0 , 1 ] , Error as follow
f ( x ) − p n ( x ) = E ( x ) = f n + 1 ( ξ ) ( n + 1 ) ! ∏ i = 0 n ( x − x i ) f(x) - p_n(x) = E(x) = \frac{f^{n+1}(\xi)}{(n+1)!}\prod_{i=0}^{n}{(x-x_i)} f ( x ) − p n ( x ) = E ( x ) = ( n + 1 )! f n + 1 ( ξ ) ∏ i = 0 n ( x − x i )
where
n n n is the degree of the polynomial (n = 5 n=5 n = 5 )
f n + 1 ( ξ ) f^{n+1}(\xi) f n + 1 ( ξ ) is ( n + 1 ) -th (n+1)\text{-th} ( n + 1 ) -th derivate of f f f
Derivate of s i n ( x ) sin(x) s in ( x ) every 4 terms is s i n ( x ) , c o s ( x ) , − s i n ( x ) , − c o s ( x ) sin(x), cos(x), -sin(x), -cos(x) s in ( x ) , cos ( x ) , − s in ( x ) , − cos ( x ) . Therefore the 6th derivative is − c o s ( x ) -cos(x) − cos ( x )
Here h = b − a n = 1 5 h=\frac{b-a}{n}=\frac{1}{5} h = n b − a = 5 1 and M = m a x 0 ≤ t ≤ 1 ∣ − c o s ( t ) ∣ = 1 − c o s ( 1 ) = 2 s i n 2 ( 1 2 ) M = max_{0\leq t\leq 1}|-cos(t)| = 1 - cos(1) = 2sin^2(\frac{1}{2}) M = ma x 0 ≤ t ≤ 1 ∣ − cos ( t ) ∣ = 1 − cos ( 1 ) = 2 s i n 2 ( 2 1 )
Therefore ∣ E ( x ) ∣ = ∣ f ( x ) − s i n ( x ) ∣ ≤ M 4 ( n + 1 ) h n + 1 = 2 s i n 2 ( 1 2 ) 4 ( 6 ) ( 1 / 5 ) 6 ≈ 1.225860517684960 × 10 − 6 |E(x)| = |f(x) - sin(x)| \leq \frac{M}{4(n+1)}h^{n+1}=\frac{2sin^2(\frac{1}{2})}{4(6)}(1/5)^6 \approx 1.225860517684960×10^{−6} ∣ E ( x ) ∣ = ∣ f ( x ) − s in ( x ) ∣ ≤ 4 ( n + 1 ) M h n + 1 = 4 ( 6 ) 2 s i n 2 ( 2 1 ) ( 1/5 ) 6 ≈ 1.225860517684960 × 1 0 − 6
b. To achieve maximum error of 10 − 8 10^{-8} 1 0 − 8 , We have
∣ f ( x ) − s i n ( x ) ∣ ≤ m a x 0 ≤ t ≤ 1 ∣ s i n ( n + 1 ) ( t ) ∣ 4 ( n + 1 ) ∗ n n + 1 = 10 − 8 |f(x) - sin(x)| \leq\frac{max_{0\leq t\leq 1}|sin^{(n+1)}(t)|}{4(n+1)*n^{n+1}} = 10^{-8} ∣ f ( x ) − s in ( x ) ∣ ≤ 4 ( n + 1 ) ∗ n n + 1 ma x 0 ≤ t ≤ 1 ∣ s i n ( n + 1 ) ( t ) ∣ = 1 0 − 8
derivative of s i n ( x ) sin(x) s in ( x ) cycles every 4 term, thus the max value of ∣ s i n ( n + 1 ) ( t ) ∣ |sin^{(n+1)}(t)| ∣ s i n ( n + 1 ) ( t ) ∣ over [ 0 , 1 ] [0,1] [ 0 , 1 ] is 1
Thus we need to solve for n n n in 1 4 ( n + 1 ) n n + 1 = 10 − 8 → n ≈ 7 (through trial and error) \frac{1}{4(n+1)n^{n+1}}=10^{-8} \rightarrow n\approx 7 \text{ (through trial and error)} 4 ( n + 1 ) n n + 1 1 = 1 0 − 8 → n ≈ 7 (through trial and error)
Hence considering to use polynomial degree seven to achieve the desired error bound.
Problem 6 [3 points] You are given the values of x \sqrt{x} x at three points
(a) [2 points] Construct the interpolating polynomial interpolating these data.
(b) [1 points] Using this polynomial, approximate 1.5 \sqrt{1.5} 1.5 .
Answer :
a. To construct the interpolating polynomial for these data, we will use Lagrange basis
P ( x ) = ∑ i = 0 n − 1 y i L i ( x ) P(x)=\sum_{i=0}^{n-1}{y_i}{L_i(x)} P ( x ) = ∑ i = 0 n − 1 y i L i ( x )
where L i ( x ) L_i(x) L i ( x ) is the i -th i\text{-th} i -th Lagrange basis polynomial, defined as
L i ( x ) = ∏ j = 0 , j ≠ i n − 1 x − x j x i − x j L_i(x) = \prod_{j=0,j\neq i}^{n-1}\frac{x-x_j}{x_i-x_j} L i ( x ) = ∏ j = 0 , j = i n − 1 x i − x j x − x j
With y ( x ) = x y(x) = \sqrt{x} y ( x ) = x , and data point x 0 = 1 , y 0 = 1 ; x 1 = 4 , y 1 = 2 ; x 2 = 9 , y 2 = 3 x_0=1,y_0=1;x_1=4,y_1=2;x_2=9,y_2=3 x 0 = 1 , y 0 = 1 ; x 1 = 4 , y 1 = 2 ; x 2 = 9 , y 2 = 3
P ( x ) = ∑ i = 0 2 y i L i ( x ) where L i ( x ) = ∏ j = 0 , j ≠ i 2 x − x j x i − x j P(x)=\sum_{i=0}^{2}{y_i}{L_i(x)} \text{ where } L_i(x) = \prod_{j=0,j\neq i}^{2}\frac{x-x_j}{x_i-x_j} P ( x ) = ∑ i = 0 2 y i L i ( x ) where L i ( x ) = ∏ j = 0 , j = i 2 x i − x j x − x j
L 0 ( x ) = ( x − x 1 ) ( x − x 2 ) ( x 0 − x 1 ) ( x 0 − x 2 ) = ( x − 4 ) ( x − 9 ) ( 1 − 4 ) ( 1 − 9 ) = ( x − 4 ) ( x − 9 ) 24 L_0(x) = \frac{(x-x_1)(x-x_2)}{(x_0-x_1)(x_0-x_2)} = \frac{(x-4)(x-9)}{(1-4)(1-9)} = \frac{(x-4)(x-9)}{24} L 0 ( x ) = ( x 0 − x 1 ) ( x 0 − x 2 ) ( x − x 1 ) ( x − x 2 ) = ( 1 − 4 ) ( 1 − 9 ) ( x − 4 ) ( x − 9 ) = 24 ( x − 4 ) ( x − 9 )
L 1 ( x ) = ( x − x 0 ) ( x − x 2 ) ( x 1 − x 0 ) ( x 1 − x 2 ) = ( x − 1 ) ( x − 9 ) ( 4 − 1 ) ( 4 − 9 ) = ( x − 1 ) ( 9 − x ) 15 L_1(x) = \frac{(x-x_0)(x-x_2)}{(x_1-x_0)(x_1-x_2)}=\frac{(x-1)(x-9)}{(4-1)(4-9)}=\frac{(x-1)(9-x)}{15} L 1 ( x ) = ( x 1 − x 0 ) ( x 1 − x 2 ) ( x − x 0 ) ( x − x 2 ) = ( 4 − 1 ) ( 4 − 9 ) ( x − 1 ) ( x − 9 ) = 15 ( x − 1 ) ( 9 − x )
L 2 ( x ) = ( x − x 0 ) ( x − x 1 ) ( x 2 − x 0 ) ( x 2 − x 1 ) = ( x − 1 ) ( x − 4 ) ( 9 − 1 ) ( 4 − 1 ) = ( x − 4 ) ( x − 1 ) 40 L_2(x) = \frac{(x-x_0)(x-x_1)}{(x_2-x_0)(x_2-x_1)}=\frac{(x-1)(x-4)}{(9-1)(4-1)} = \frac{(x-4)(x-1)}{40} L 2 ( x ) = ( x 2 − x 0 ) ( x 2 − x 1 ) ( x − x 0 ) ( x − x 1 ) = ( 9 − 1 ) ( 4 − 1 ) ( x − 1 ) ( x − 4 ) = 40 ( x − 4 ) ( x − 1 )
P ( x ) = y 0 L 0 ( x ) + y 1 L 1 ( x ) + y 2 L 2 ( x ) = 1 ∗ ( x − 4 ) ( x − 9 ) 24 + 2 ∗ ( x − 1 ) ( 9 − x ) 15 + 3 ∗ ( x − 4 ) ( x − 1 ) 40 P(x) = y_0L_0(x) + y_1L_1(x) + y_2L_2(x) = 1 * \frac{(x-4)(x-9)}{24} + 2*\frac{(x-1)(9-x)}{15} + 3*\frac{(x-4)(x-1)}{40} P ( x ) = y 0 L 0 ( x ) + y 1 L 1 ( x ) + y 2 L 2 ( x ) = 1 ∗ 24 ( x − 4 ) ( x − 9 ) + 2 ∗ 15 ( x − 1 ) ( 9 − x ) + 3 ∗ 40 ( x − 4 ) ( x − 1 )
The interpolating polynomial P ( x ) = ( x − 4 ) ( x − 9 ) 24 + 2 ( x − 1 ) ( 9 − x ) 15 + 3 ( x − 4 ) ( x − 1 ) 40 P(x)=\frac{(x-4)(x-9)}{24} + \frac{2(x-1)(9-x)}{15} + \frac{3(x-4)(x-1)}{40} P ( x ) = 24 ( x − 4 ) ( x − 9 ) + 15 2 ( x − 1 ) ( 9 − x ) + 40 3 ( x − 4 ) ( x − 1 )
b. The approximation of P ( 1.5 ) = ( 1.5 − 4 ) ( 1.5 − 9 ) 24 + 2 ( 1.5 − 1 ) ( 9 − 1.5 ) 15 + 3 ( 1.5 − 4 ) ( 1.5 − 1 ) 40 = 1.1875 P(\sqrt{1.5})=\frac{(1.5-4)(1.5-9)}{24} + \frac{2(1.5-1)(9-1.5)}{15} + \frac{3(1.5-4)(1.5-1)}{40}=1.1875 P ( 1.5 ) = 24 ( 1.5 − 4 ) ( 1.5 − 9 ) + 15 2 ( 1.5 − 1 ) ( 9 − 1.5 ) + 40 3 ( 1.5 − 4 ) ( 1.5 − 1 ) = 1.1875
Problem 7 [7 points] Let f ( x ) = s i n ( x ) ( 1 + 20 x ) 2 f(x) = \frac{sin(x)}{(1+20x)^2} f ( x ) = ( 1 + 20 x ) 2 s in ( x ) . Interpolate this function over x ∈ [ − 1 , 1 ] x \in [−1, 1] x ∈ [ − 1 , 1 ] using
(a) [2 points] polynomial interpolation of degree n = 15 n = 15 n = 15 at equally spaced points.
Then evaluate this polynomial at N = 100 N = 100 N = 100 equally spaced points.
Denote the interpolating polynomial by p ( x ) p(x) p ( x ) . Plot
f ( x ) f(x) f ( x ) and p ( x ) p(x) p ( x ) versus x x x at the interpolation points and at the N N N points (on the same plot);
∣ f ( x ) − p ( x ) ∣ |f(x) − p(x)| ∣ f ( x ) − p ( x ) ∣ versus x x x at the N N N points.
You can use the polyfit
function. See the linspace
function.
(b) [2 points] Repeat (a) but now using Chebyshev points.
(c) [2 points] Repeat (a) but now using spline interpolation at n + 1 n + 1 n + 1 equally spaced points. See the spline
function.
(d) [1 points] Discuss the accuracies of your results.
Submit your plots (6 in total) and the Matlab code producing them. Name your Matlab file interp_problem.m
.
Answer
f ( x ) f(x) f ( x ) implementation in matlab are as follow:
f = @(x) sin(x)./(( 1 + 20 *x).^2);
a. The following is a snippet of interp_problem.m
for polynomial interpolation of degree n = 15 n=15 n = 15
% (a) Polynomial interpolation of degree n = 15 at equally spaced points
% Define the number of interpolation points and the degree of the polynomial
n = 15 ;
N = 100 ;
% Generate n+1 equally spaced points in the interval [-1, 1]
x = linspace(- 1 , 1 , n+ 1 );
y = f(x);
% Interpolate using polyfit
p_coeff = polyfit(x, y, n);
% Evaluate the interpolating polynomial at N equally spaced points
x_N = linspace(- 1 , 1 , N);
p_N = polyval(p_coeff, x_N);
% Plot f(x) and p(x) on the same graph
figure;
plot(x_N, f(x_N), 'b-' , x_N, p_N, 'r--' , x, y, 'go' );
legend( 'f(x)' , 'p(x)' , 'Interpolation Points' );
title( 'f(x) and p(x) vs. x' );
xlabel( 'x' );
ylabel( 'y' );
% Plot the absolute error |f(x) - p(x)| at the N points
figure;
plot(x_N, abs(f(x_N) - p_N), 'm-' );
title( 'Absolute Error |f(x) - p(x)| vs. x' );
xlabel( 'x' );
ylabel( 'Error' );
b. The following is a snippet of interp_problem.m
for Cheybyshev points
% (b) Polynomial interpolation using Chebyshev points
% Generate Chebyshev points in the interval [-1, 1]
x_cheb = cos(( 2 *( 1 :n+ 1 )- 1 )* pi /( 2 *n));
y_cheb = f(x_cheb);
% Interpolate using polyfit
p_cheb_coeff = polyfit(x_cheb, y_cheb, n);
% Evaluate the interpolating polynomial at N equally spaced points
p_cheb_N = polyval(p_cheb_coeff, x_N);
% Plot f(x) and p(x) using Chebyshev points on the same graph
figure;
plot(x_N, f(x_N), 'b-' , x_N, p_cheb_N, 'r--' , x_cheb, y_cheb, 'go' );
legend( 'f(x)' , 'p(x) with Chebyshev' , 'Interpolation Points' );
title( 'f(x) and p(x) with Chebyshev vs. x' );
xlabel( 'x' );
ylabel( 'y' );
% Plot the absolute error |f(x) - p(x)| using Chebyshev points at the N points
figure;
plot(x_N, abs(f(x_N) - p_cheb_N), 'm-' );
title( 'Absolute Error |f(x) - p(x) with Chebyshev| vs. x' );
xlabel( 'x' );
ylabel( 'Error' );
c. The following is a snippet of interp_problem.m
through spline interpolation at n + 1 n + 1 n + 1 equally spaced points.
% (c) Spline interpolation at n+1 equally spaced points
% Evaluate the function at n+1 equally spaced points
y_spline = f(x);
% Use the spline function to get the piecewise polynomial representation
pp = spline(x, y_spline);
% Evaluate the spline at N equally spaced points
spline_N = ppval(pp, x_N);
% Plot f(x) and the spline on the same graph
figure;
plot(x_N, f(x_N), 'b-' , x_N, spline_N, 'r--' , x, y_spline, 'go' );
legend( 'f(x)' , 'spline(x)' , 'Interpolation Points' );
title( 'f(x) and spline(x) vs. x' );
xlabel( 'x' );
ylabel( 'y' );
% Plot the absolute error |f(x) - spline(x)| at the N points
figure;
plot(x_N, abs(f(x_N) - spline_N), 'm-' );
title( 'Absolute Error |f(x) - spline(x)| vs. x' );
xlabel( 'x' );
ylabel( 'Error' );
d. Discussion
The polynomial interpolation using equally spaced points might show oscillations near endpoints due to Runge phenomenon (oscillations near the endpoints of the interpolated interval become pronounced). We saw oscillation in the error graph here.
Polynomial interpolation using Chebyshev points should mitigate the oscillations
The spline interpolation will provide a piecewise polynomial that should fit the function smoothly and might offer better accuracy than polynomial interpolation
Problem 8 [4 points] Given the three data points ( − 1 , 1 ) , ( 0 , 0 ) , ( 1 , 1 ) (−1, 1), (0, 0), (1, 1) ( − 1 , 1 ) , ( 0 , 0 ) , ( 1 , 1 ) , determine the interpolating polynomial of degree two using:
a. [1 point] monomial basis
b. [1 point] Lagrange basis
c. [1 point] Newton basis
[1 point] Show that the three representations give the same polynomial.
Answer :
a. Monomial basis
The monomial basis for a polynomial of degree two is given by: p ( x ) = a 0 + a 1 ∗ x + a 2 ∗ x 2 p(x)=a_0+a_1*x+a_2*x^2 p ( x ) = a 0 + a 1 ∗ x + a 2 ∗ x 2
The linear system as follow
a 0 − a 1 + a 2 = 1 a_0-a_1+a_2=1 a 0 − a 1 + a 2 = 1
a 0 = 0 a_0=0 a 0 = 0
a 0 + a 1 + a 2 = 1 a_0+a_1+a_2=1 a 0 + a 1 + a 2 = 1
Solving this system to obtain the a 0 = 0 , a 1 = 0 , a 2 = 1 a_0=0,a_1=0, a_2=1 a 0 = 0 , a 1 = 0 , a 2 = 1
Thus monomial basis of this polynomial of degree two is p ( x ) = x 2 p(x) = x^2 p ( x ) = x 2
b. Lagrange basis
The Lagrange basis for a polynomial of degree two is given by: p ( x ) = ∑ j = 0 2 y j L j ( x ) = f ( x 0 ) L 0 ( x ) + f ( x 1 ) L 1 ( x ) + f ( x 2 ) L 2 ( x ) p(x)=\sum_{j=0}^{2}{y_j}{L_j(x)} = f(x_0)L_0{(x)} + f(x_1)L_1{(x)} + f(x_2)L_2{(x)} p ( x ) = ∑ j = 0 2 y j L j ( x ) = f ( x 0 ) L 0 ( x ) + f ( x 1 ) L 1 ( x ) + f ( x 2 ) L 2 ( x )
where
L 0 ( x ) = ( x − x 1 ) ( x − x 2 ) ( x 0 − x 1 ) ( x 0 − x 2 ) = x ( x − 1 ) 2 L_0(x) = \frac{(x-x_1)(x-x_2)}{(x_0-x_1)(x_0-x_2)} = \frac{x(x-1)}{2} L 0 ( x ) = ( x 0 − x 1 ) ( x 0 − x 2 ) ( x − x 1 ) ( x − x 2 ) = 2 x ( x − 1 )
L 1 ( x ) = ( x − x 0 ) ( x − x 2 ) ( x 1 − x 0 ) ( x 1 − x 2 ) = − x ( x − 1 ) L_1(x) = \frac{(x-x_0)(x-x_2)}{(x_1-x_0)(x_1-x_2)}=-x(x-1) L 1 ( x ) = ( x 1 − x 0 ) ( x 1 − x 2 ) ( x − x 0 ) ( x − x 2 ) = − x ( x − 1 )
L 2 ( x ) = ( x − x 0 ) ( x − x 1 ) ( x 2 − x 0 ) ( x 2 − x 1 ) = x ( x + 1 ) 2 L_2(x) = \frac{(x-x_0)(x-x_1)}{(x_2-x_0)(x_2-x_1)}=\frac{x(x+1)}{2} L 2 ( x ) = ( x 2 − x 0 ) ( x 2 − x 1 ) ( x − x 0 ) ( x − x 1 ) = 2 x ( x + 1 )
Thus p ( x ) = 1 ∗ x ( x − 1 ) 2 + 0 ∗ ( − x ( x − 1 ) ) + x ( x + 1 ) 2 = x 2 p(x) = 1*\frac{x(x-1)}{2} + 0*(-x(x-1)) + \frac{x(x+1)}{2} = x^2 p ( x ) = 1 ∗ 2 x ( x − 1 ) + 0 ∗ ( − x ( x − 1 )) + 2 x ( x + 1 ) = x 2
Thus Lagrange basis of this polynomial of degree two is p ( x ) = x 2 p(x) = x^2 p ( x ) = x 2
c. Newton basis
The Newton basis for a polynomial of degree two is given by: p ( x ) = f ( x 0 ) + ( x − x 0 ) f [ x 0 , x 1 ] + ( x − x 0 ) ( x − x 1 ) f [ x 0 , x 1 , x 2 ] p(x)=f(x_0)+(x-x_0)f[x_0, x_1] + (x-x_0)(x-x_1)f[x_0, x_1, x_2] p ( x ) = f ( x 0 ) + ( x − x 0 ) f [ x 0 , x 1 ] + ( x − x 0 ) ( x − x 1 ) f [ x 0 , x 1 , x 2 ]
where
f [ x 0 , x 1 ] = f ( x 1 ) − f ( x 0 ) x 1 − x 0 = 0 − 1 0 + 1 = − 1 f[x_0,x_1]=\frac{f(x_1)-f(x_0)}{x_1-x_0} = \frac{0-1}{0+1} = -1 f [ x 0 , x 1 ] = x 1 − x 0 f ( x 1 ) − f ( x 0 ) = 0 + 1 0 − 1 = − 1
f [ x 0 , x 1 , x 2 ] = f [ x 1 , x 2 ] − f [ x 0 , x 1 ] x 2 − x 0 = 1 + 1 1 + 1 = 1 f[x_0,x_1,x_2]=\frac{f[x_1, x_2]-f[x_0, x_1]}{x_2-x_0} = \frac{1+1}{1+1} = 1 f [ x 0 , x 1 , x 2 ] = x 2 − x 0 f [ x 1 , x 2 ] − f [ x 0 , x 1 ] = 1 + 1 1 + 1 = 1
We have f [ x 1 , x 2 ] = f ( x 2 ) − f ( x 1 ) x 2 − x 1 = 1 − 0 1 − 0 = 1 f[x_1,x_2]=\frac{f(x_2)-f(x_1)}{x_2-x_1} = \frac{1-0}{1-0} = 1 f [ x 1 , x 2 ] = x 2 − x 1 f ( x 2 ) − f ( x 1 ) = 1 − 0 1 − 0 = 1
Thus p ( x ) = 1 + ( x + 1 ) ( − 1 ) + ( x + 1 ) ( x ) ∗ 2 = 1 − x − 1 + ( x 2 + x ) = x 2 p(x)=1+(x+1)(−1)+(x+1)(x)*2 =1 - x-1 + (x^2+x)=x^2 p ( x ) = 1 + ( x + 1 ) ( − 1 ) + ( x + 1 ) ( x ) ∗ 2 = 1 − x − 1 + ( x 2 + x ) = x 2
Thus Newton basis of this polynomial of degree two is p ( x ) = x 2 p(x) = x^2 p ( x ) = x 2
Therefore, we prove that all three basis yield the same polynomial for degree two.