# Vandermonde Matrix System for polynomial interpolation

## Introduction

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]

plot(x,y,'k.','markersize',30);
snapnow;

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);

plot(xs,ys,'r','linewidth',1);

hold on;
plot(x,y,'k.','markersize',30);
title('Using vander','fontsize',18);
snapnow;

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);
snapnow;

Back to the top

## Exercises

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)$$

Back to the top

Back to the top