COT450 Spring 0 Homework VI This assignment has seven problems. The assignment is due in class on Tuesday, April 0, 0. There are seven regular problems and two computer problems (using MATLAB). For written problems, you need to show your work and it is insufficient to just give the results or answers. For the computer problems, turn in your results (e.g., graphs, plots, simple analysis and so on) and also a printout of your (MATLAB) code. Problem (5pts). What is the basic distinction between interpolation and approximation of a function?. Is Interpolation an appropriate procedure for fitting a function to noisy data? If so, why? and if not, what is a good alternative? 3. (a) For a given set of data points (t i, y i ), i =,..., n, rank the following three methods for polynomial interpolation according to the cost of determining the interpolant (i.e., determining the coefficients of the basis functions), from for the cheapest to 3 for the most expensive: Monomial basis, Lagrange Basis and Newton basis. (b) Which of the three methods has the best-conditioned basis matrix A? (c) For which of the three methods is evaluating the resulting interpolant at a given point the most expensive? 4. Why is interpolation by a polynomial of high degree often unsatisfactory? 5. In fitting a large number of data points, what is the main advantage of piecewise polynomial interpolation over interpolation by a single polynomial?. In approximation, function could be close to the points and not necessarily passes through those points. Interpolating function fits given data exactly.. Interpolation is inappropriate, least squares approximation should be used. 3. (a) Monomial basis (3), Newton basis(), Lagrange basis () (b) Newton (c) Lagrange 4. it s expansive to determine and evaluate. In some bases, coefficients of polynomial may be poorly determined due to ill-conditioning of linear system to be solved. High degree polynomial necessarily has lots of wiggles which may bear no relation to the data to be fit. Polynomial may pass through required data point, but it may oscillate wildly between data points
5. large number of data points can be fit with low-degree polynomials. Problem (5pts). How many times is a Hermite cubic interpolant continuously differentiable?. How many times is a cubic spline interpolant continuously differentiable? 3. For Lagrange polynomial interpolation of n data points (t i, y i ), i =,..., n,. once. twice (a) What is the degree of each polynomial function l j (t) in the Lagrange basis? (b) What function results if we sum the n functions in the Lagrange basis (i.e., if we take g(t) = l (t) +... + l n (t), what function g(t) results)? 3. (a) n- (b) one. The proof is quite simple. g(t) = l (t) +... + l n (t) could be taken as interpolating zeroth order polynomial (constant function) with value i.e. y i =. As the interpolating polynomial is unique (property of Polynomial Interpolation, since there are n data points and degree is n ) therefore g(t) = implying summation is. Problem 3 (5pts) Given the three data points (, ), (0, 0), (, ), determine the interpolating polynomial of degree two:. Using the monomial basis. Using the Lagrange basis 3. Using the Newton basis Show that the three representations give the same polynomial.. The linear system using the monomial basis is x 0 0 x x 3 = 0 () Solving this system by Gaussian elimination, we obtain x = [00] T so the interpolating polynomial is p(t) = t.
. The form of a polynomial of degree two using the Lagrange basis is (t t )(t t 3 ) p(t) = y (t t )(t t 3 ) + y (t t )(t t 3 ) (t t )(t t 3 ) + y (t t )(t t ) 3 (t 3 t )(t 3 t ) substituting the data for this problem, the polynomial becomes (t 0)(t ) p(t) = ( 0)( ) t(t ) p(t) = + which is equivalent to the polynomial in part 3. The linear system using the Newton basis is 0 0 x 0 x x 3 (t + )(t ) (t + )(t 0) + 0 + (0 + )(0 ) ( + )( 0) t(t + ) = 0 () Solving this system by forward substitution, we obtain x = [ ] T so the interpolating polynomial is p(t) = (t + ) + (t + t. Which is equivalent to the polynomial in first part Problem 4 (5pts) How many multiplications are required to evaluate a polynomial p(t) of degree n at a given point t. represented in the monomial basis?. represented in the Lagrange basis? 3. represented in the Newton basis?. Without Horner s method,p n (t) = x n t n + x n t n +... + x. It 4 k is computer from scratch at each step, then it takes (n )(n ) multiplications to computer t k and n multiplications by the x k, for a total of n multiplications. If tk is computed inductively using t k from previous step, then it takes n multiplications to compute t n and n multiplications by the x k for a total of (n ) multiplications. With Horner s method, p n (t) = x + t(x + t(... (x n + x n t)...)), which requires n multiplications. (t t )(t t 3 )... (t t n ) p n (t) = y (t t )(t t 3 )... (t t n ) + + y (t t )(t t )... (t t n ) n (t n t )(t n t )... (t n t n ) 3
for a given polynomial, y and the denominators are constants, so we have p n (t) = c (t t )(t t 3 )... (t t n ) + + c n (t t )(t t )... (t t n ) Each basis function requires n multiplications, so for n bais function the total is n total multiplications. 3. Without the Horner s method, p n (t) = c (t t )(t t 3 ) +... + c n (t t )(t t )... (t t n ), which is requires n(n )/ multiplications. With Horner s method, p n (t) = x + (t t )(x + (t t )(... (x n (t t n ))...)) which requires n multiplications. Problem 5 (0pts) Express the following polynomial in the correct form for evaluation by Horner s method:. p(t) = 5t 3 3t + 7t. p(t) = t 3. p(t) = 5t 3 3t + 7t p(t) = + t(7 + (t( 3 + 5t))). p(t) = t 3 p(t) = + t(t(t)) Problem 6 (5pts). For a given set of data points t,..., t n, define the function π(t) by Show that π(t) = (t t )(t t )...(t t n ). π (t j ) = (t j t )(t j t )...(t j t j )(t j t j+ )...(t j t n ).. Use the result of the previous part to show that the jth Lagrange basis function can be expressed as π(t) (t t j )π (t j ). 4
. Differentiating π(t) with respect to t π (t) = (t t ) (t t )...(t t n ) + (t t )(t t )...(t t n ) +... + (t t )(t t )...(t t j )... (t t n ) +... + (t t )(t t )...(t t j )... (t t n ) π (t) = (t t )...(t t j )... (t t n ) + (t t )...(t t j )... (t t n ) +... + (t t )(t t )...(t t j )(t t j+ )... (t t n ) +... + (t t )(t t )...(t t j )... (t t n ) When we evaluating at t j there will be only one term which will not contain (t t j ) π (t j ) = (t j t )(t j t )...(t j t j )(t j t j+ )...(t j t n ).. the j th Lagrangian basis is given by n k=,k j (t t k) n k=,k j (t t k) (t t )(t t )...(t t j )(t t j+ )...(t t n) (t j t )(t j t )...(t j t j )(t j t j+ )...(t j t n) multiplying numerator and denominator by (t t j ) we get (t t )(t t )...(t t j )(t t j )(t t j+ )...(t t n) (t t j )(t j t )(t j t )...(t j t j )(t j t j+ )...(t j t n) π(t). (t t j )π (t j ) Problem 7 (5pts) In general, is it possible to interpolate n data points by a piecewise quadratic polynomial, with knots at the given data points, such that the interpolant is. once continuously differentiable?. twice continuously differentiable? Computer Problem (0pts) Interpolating the data points t: 0 4 9 6 5 36 y: 0 3 4 5 6 ----------------------------------------------------- t: 49 64 y: 7 8 5
should given an approximation to the square root function.. Compute the polynomial of degree eight that interpolates these nine data points. Plot the resulting polynomial as well as the corresponding values given by the MATLAB function sqrt over the domain [0, 64].. Use a cubic spline routine (MATLAB function spline) to interpolate the same data and again plot the resulting curve along with the MATLAB function sqrt over the same domain as above. 3. Which of the two interpolants is more accurate over most of the domain? 4. Which of the two interpolants is more accurate between 0 and? For this problem, you need to implement a short piece of MATLAB code that does the polynomial interpolation (part ). You are allowed to use any method (basis) to compute the polynomial interpolation. For part, you are allowed to use the MATLAB functions spline and ppval. In case you do not know how to use the two MATLAB functions, use help to learn more about them and try a few simple examples first. An example of plotting sqrt function and a function f(t) on the domain [0, 64] is > t = 0:0.:64; > y_ = f(t); > y_ = sqrt(t); > plot(t, y_, -b, t, y_, -r ); 7.6. function cp07_06 % interpolation of square root function t = [0; ; 4; 9; 6; 5; 36; 49; 64]; y = [0:8]'; 3 p = polyfit(t,y,8); pp = spline(t,y); 4 ts = linspace(0,64,00)'; yr = sqrt(ts); yp = polyval(p,ts); ys =... 5 figure; hold on; plot(t,y,'ko',ts,yr,'k-',ts,yp,'b--',ts,ys,'r-.'); 6 title('computer Problem 7.6(a)-(c) -- Interpolants to Square Root'); 7 xlabel('t'); ylabel('y'); axis([0,64,0,8]); 8 legend('data points','square root','polynomial','spline',0); 9 ts = linspace(0,,00)'; yr = sqrt(ts); yp = polyval(p,ts); ys =... 0 figure; plot(t(:),y(:),'ko',ts,yr,'k-',ts,yp,'b--',ts,ys,'r-.'); title('computer Problem 7.6(d) -- Interpolants to Square Root'); xlabel('t'); ylabel('y'); axis([0,,0,]); 3 legend('data points','square root','polynomial','spline',0); 6
Computer Problem (0pts) The gamma function is defined by Γ(x) = 0 t x e t dt, x > 0. For an integer argument n, the gamma function has the value so interpolating the data points Γ(n) = (n )!, t: 3 4 5 y: 6 4 should yield an approximation to the gamma function over the given range.. Compute the polynomial of degree four that interpolates these five data points. Plot the resulting polynomial as well as the corresponding values given by the MATLAB function gamma over the domain [, 5].. Use a cubic spline routine to interpolate the same data and again plot the resulting curve along with the MATLAB function gamma over the domain [, 5]. 3. Which of the two interpolants is more accurate over most of the domain? 4. Which of the two interpolants is more accurate between and? 7.7. function cp07_06 % interpolation of gamma function t = [:5]'; y = [; ; ; 6; 4]; p = polyfit(t,y,8); pp = spline(t,y); 3 ts = linspace(0,5,00)'; yr = gamma(ts); yp = polyval(p,ts); ys =... 4 figure; hold on; plot(t,y,'ko',ts,yr,'k-',ts,yp,'b--',ts,ys,'r-.'); 5 title('computer Problem 7.7(a)-(c) -- Interpolants to Gamma... Function'); xlabel('t'); 6 ylabel('y'); legend('data points','gamma... function','polynomial','spline',); 7 ts = linspace(,,00)'; yr = gamma(ts); yp = polyval(p,ts); ys =... 8 figure; plot(t(:),y(:),'ko',ts,yr,'k-',ts,yp,'b--',ts,ys,'r-.'); 9 title('computer Problem 7.7(d) -- Interpolants to Gamma Function');... xlabel('t'); 0 ylabel('y'); legend('data points','gamma... function','polynomial','spline',4); 7