HW FIVE

  1. 5.4

    (a)

    $\displaystyle p(x) = \frac{(x-1)(x-2)}{2} -2 x (x-2) -\frac{x(x-1)}{2}.$

    (b)

    $\displaystyle p(x) = x(x-1)(x-2)\left(
\frac{1}{2x} + \frac{2}{x-1}-
\frac{1}{2(x-2)}\right).$

    (c)

    If $0 \le x\le 1$ then $p_1(x) = 1+x$.

    If $1\le x \le 2$ then $p_2(x) = 5-3x$.

    (d)

    Setting for the first cubic polynomial

    $\displaystyle s_1(x) = a_1 +b_1 x + c_1 x^2 + d_1 x^3,$

    and for the second cubic polynomial

    $\displaystyle s_2(x) = a_2 +b_2 (x-1) + c_2 (x-1)^2 + d_2 (x-1)^3,$

    we obtain the system of equations
    $\displaystyle a_1=1, a_1+b_1+c_1+d_1=2, a_2 = 2, a_2+b_2+c_2+d_2=-1,$      
    $\displaystyle b_1+2 c_1 + 3 d_1 - b_2 = 0, 2 c_1+6 d_1 - 2 c_2 =0,c_1=0, 2 c+2 + 6 d_2=0$      

    Solving these equations we obtain
    $\displaystyle s_1(x) = 1 + 2 x - x^3,$      
    $\displaystyle s_2(x) = 2 - (x-1) - 3 (x-1)^2 + (x-1)^3$      
           

  2. 5.6

    (a)

    $\displaystyle p(x) = x(x-2)(x-3) - x (x-1)(x-3) + x (x-1)(x-2).$

    Simplifying this we obtain

    $\displaystyle p(x) = 5*x - 4*x^2 + x^3.$ (46)

    (b)

    $\displaystyle p(x) = x (x-1)(x-2)(x-3) \left( 1/(x-1) - 1 /(x-2) + 1 / (x-3)\right).$

    This expression simplifies to (47).

    (c)


    $\displaystyle p(x) = \begin{bmatrix}
2 x {\rm\ for\ \ } 0\le x\le 1\\
2 {\rm\ for \ \ }1\le x \le 2\\
2+4(x-2){\rm\ for \ \ }2\le x \le 3\end{bmatrix}$      

    (d) Since there are four data points, the (47) gets supplemented with

    $\displaystyle s_3(x) = a_3+ b_3 (x-2) + c_3(x-2)^2+d_3(x-2)^3,$    

    and the equations become
    $\displaystyle a_1=0,a_1+b_1+c_1+d_1=2,a_2=2,a_2+b_2+c_2+d_2=2,$      
    $\displaystyle a_3=2,a_3+b_3+c_3+d_3=6,
b_1+2c_1+3d_1-b_2=0,2c_1+6d_1-c_2=0,$      
    $\displaystyle d_1=d_2,b_2+2c_2+3d_2-b_3=0,d_2=d_3,2c_2+6d_2-2c_3=0$      

    The solution of these equations are given by

    $\displaystyle a_1= 0, b_1= \frac{44}{9}, c_1=-4, d_1=\frac{10}{9},$      
    $\displaystyle a_2= 2,b_2=\frac{2}{9},c_2= -\frac{4}{3},d_2= \frac{10}{9},$      
    $\displaystyle a_3=2,b_3= \frac{8}{9},
c_3= 2,d_3=\frac{10}{9}$      

  3. 5.18

    (a) Construct a cubic polynomial

    $\displaystyle p(x) = a + b x + c x ^2 + d x^3,$ (47)

    and choose $N\ge 4$ distinct points: $x_i, \ i = 1\dots N$. Furthermore, construct $N$ points $y_i=g(x_i), \ i=1\dots N$.

    Then the cubic polynomial (48) is a global interpolation polynomial for the points $(x_i,y_i)$ with $i=1\dots N$.

    Does $p(x)$ constitutes a cubic spline for these $N$ points? Note that

    Consequently, $p(x)$ does satisfy all requirements for it to be a cubic spline for these points.

    As we learned in class, the cubic spline has a freedom to have two additional conditions. Choosing the clamped spline will specify the derivatives at the beginning and the end. In other words, it will require that $p'(x_1)$ and $p'(x_N)$ be given. Note that $p'(x_1)=p'(x_N)=b$.

    Therefore $p(x)$ does represent the clamped cubic spline interpolating points $(x_i,y_i)$ for $i=1\dots N$.

    Requirement of $p(x)$ to be a natural cubic spline means that $p''(x_1)=p''(x_2)=0.$ This requirement translates into $c=0$. Therefore if $c=0$, the $p(x)$ does constitutes a natural cubic spline. If $c\ne 0$, then $p(x)$ is not a natural cubic spline.

  4. 5.22
    figure(1)
    X = [0, 0.005, 0.0075, 0.0125, 0.025, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,0.9, 1.0];
    Yu = [0, 0.0102, 0.0134, 0.017, 0.025, 0.0376, 0.0563, 0.0812, 0.0962, 0.1035,0.1033, 0.095, 0.0802, 0.0597, 0.034, 0];
    Yl = [0, -0.0052, -0.0064, -0.0063, -0.0064, -0.006, -0.0045, -0.0016, 0.001, 0.0036, 0.007, 0.0121, 0.017, 0.0199, 0.0178 , 0];
    x = linspace(0,1,100);yu=spline(X,Yu,x);yl=spline(X,Yl,x);
    scatter(X,Yl,'filled');
    hold on
    scatter(X,Yu,'filled');
    plot(x,yu);hold on; plot(x,yl);hold on;
    title('airfoil, spline interpolation');
    legend('lower','upper','spline1','spline2');
    

    (b)

    To build the global polynomial interpolation, let us construct Vandermonde matrix as follows:

    A = [X.^0; X;X.^2;X.^3;X.^4;X.^5;X.^6;X.^7;X.^8;X.^9;X.^10;X.^11;X.^12;X.^13;X.^14;X.^15]
    

    This matrix has a condition number about $10^{16}$, therefore no global polynomial interpolation is possible for these points. Attempts to make "Matlab Divide" of $A$ by $X$ leads to values of $10^{11}$, and the resulting interpolation function oscillates to $10^4$ between the data points.

  5. 5.23

    figure(1)
    X = [0:2:24]
    Y = [ 59 56 53 54 60 67 72 74 75 74 70 65 61]
    x=linspace(0,24,100);
    L = polyfit(X,Y,12);
    T1 =polyval(L,x);
    scatter(X,Y,'filled');hold on 
    plot(x,T1,'-r');
    T2 = spline(X,Y,x);hold on 
    plot(x,T2,'-b');hold off 
    legend('Temperature','global polynomial','spline');
    title('Temperature in Troy NY');
    

    Here we used global polynomial interpolation, not Lagrange interpolation. While there are routines for Matlab Lagrange interpolation, the resulting graph is the same. Similarly, we used the spline as oppose to B spline, because the resulting interpolating function is the same.

    We observe that spline interpolation is "better" or more physical, as a polynomial interpolation generates wiggles which are unlikely to occur in the temperature dynamic over a single day.

  6. 5.26

    We observe on the Figure 5.23 that the second derivative infinity norm is about 1, i.e. $\vert\vert f''(x)\vert\vert _\infty = 1$, and that the fourth derivative infinity norm is about 3, i.e. $\vert\vert f''(x)\vert\vert _\infty = 3 $.

    a) How many data points for piecewise linear interpolation are needed to guarantee the error is less than $10^{-8}$ ?

    According to the Theorem 5.4, the maximum error of PW linear interpolation is given by

    $\displaystyle \frac{1}{8} h^2 \vert\vert f''\vert _\infty.$

    Subsituting $10^{-8}$ for the error, and $1$ for the $\vert\vert f''\vert\vert _\infty$, we obtain

    $\displaystyle h = \sqrt{8 10^{-8}}\simeq 2.8 10^{-4}.$

    (b) How many data points for a clamped cubic spline are needed to guarantee the error is less than $10^{-8}$ ?

    According to the Theorem 5.5 the maximum error of the clamped cubic spline interpolation is given by

    $\displaystyle frac{5}{384}h^4 h^4 \vert\vert f''''\vert\vert _\infty.$

    Substituting the value of $\vert\vert f''''\vert\vert _\infty\simeq 3$ amd the value of the error $10^{-8}$ we obtain

    $\displaystyle h = \left(\frac{384 10^{-8}}{5 \cdot 3}\right)^{\frac{1}{4}}\simeq 0.0225.$