Vandermonde Matrix System for polynomial interpolation

Topics in this lab


In this lab, we will learn how to solve the Vandermonde matrix system to find the coefficients of an interpolating polynomial. We will also see how the matlab command polyfit can be used to obtain the same set of coefficients.

Back to the top

Generate the data

clear all;
close all;
N = 10;  % We will try to fit a tenth degree polynomial
x = linspace(-1,1,N+1)';
a = 3;
b = 8;
y = a + (b-a)*rand(N+1,1);   % Generate random numbers in [a,b]


Back to the top

Solving the Vandermonde system

Solve the Vandermonde system using vander

V = vander(x);
a = V\y;

Plot the results of the Vandermonde system

xs = linspace(-1,1,100);
ys = polyval(a,xs);


hold on;
title('Using vander','fontsize',18);

Back to the top

Using the polynomial interpolation available in Matlab.

Use the Matlab function polyfit

p = polyfit(x,y,N);     % Supply the degree of the polynomial
ys = polyval(p,xs);

plot(xs,ys,'ko','linewidth',1); % Plot using the 'circle' symbol
title('Using polyfit','fontsize',18);

Back to the top


For each of the following problems, use the vander function to answer the questions. Plot the data points and the curve you find.
  1. Find the slope and the y-intercept of the line that passes through the two points $(-3.2, 1.2)$ and $(5.4,-4.3)$.
  2. Find the maximum value of the parabola that passes through the three points $$(-3.2, 4.5), \quad (1.2,6.1), \quad (6.1,-3.4)$$

Compare your answers with the solutions.

Back to the top

Download this file

Download the file that created this lab here

Back to the top

Get the code

Do you want to try the above code fragments on your own? Download the Matlab script that produces this page here. (lab_9.m)

Powered by MathJax

Published with MATLAB® 8.2