

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Homework4.
1. Write a Matlab program that computes the condition numbers of V and B for n = 1,... , 20.
% CMSC/AMSC 460 Fall 2007 % Homework 4 % % Investigates the stability of polynomial interpolation % based on the power basis and the Newton basis using the % condition number of their coefficient matrices. % % Dianne O'Leary 15 Oct. 2007 % Modified by Sima Taheri, 30 Oct. 2007 % % Parameters: % X: Interpolation points which are n equally % spaced points xi between 0 and 1. % n: Number of interpolation points, n = 1,...,20. % V: Vandermonde matrix for power basis interpolation. % p(x) = d_1x^n-1 + d_2x^n-2 +... + d_n-1x + d_n, % kappaV: Condition number of matrix V. % B: Matrix for Newton basis interpolation. % p(x) = c_1+c_2(x-x1)+...+c_n(x-x1)(x-x2)...(x-xn-1), % kappaB: Condition number of matrix B. % % Outputs: % Matrices V and B for n=4. % Plot of the condition numbers vs. n % A table of the condition numbers
nmax = 20; for n=1:nmax, % Interpolation points X = linspace(0,1,n)'; % Vandermonde matrix V = vander(X);
% Generate B matrix B = zeros(n); B(1:n,1) = ones(n,1); for i=2:n B(i:n,i) = (X(i:n)-X(i-1)).*B(i:n,i-1); end
% Condition numbers kappaV(n) = cond(V); kappaB(n) = cond(B);
% Display the matrices V and B for n = 4 if (n==4) V B end end
% Plot the condition numbers as a function of n figure(1) semilogy(1:nmax, kappaV, 'r.', 1:nmax, kappaB, 'b-') legend('Condition number of Vandermonde matrix', ... 'Condition number of Newton basis matrix') xlabel('n = number of interpolation points') ylabel('\kappa')
% Make a table of the condition numbers disp('Condition numbers of Vandermonde matrix V') disp('and Newton matrix B for various dimensions n:') disp(' ') disp(' n kappa(V) kappa(B)') disp(sprintf(' %2d %7.3e %7.3e \n',[[1:nmax];kappaV; kappaB]))
0 2 4 6 8 10 12 14 16 18 20
100
102
104
106
108
1010
1012
1014
1016
1018
n = number of interpolation points
κ
Condition number of Vandermonde matrix Condition number of Newton basis matrix