// Scilab file made available as part of TEQIP-NCM-NBHM workshop: Nov 2019
// Tested on scilab version 6.0.1
// Conducted at IIT Bombay. Scilab scripts written by Sudarshan Pulapadi
// License: GPL


function V = vandermode(x)
  // returns vandermonde matrix with first COLUMN as ones
  // each consecutive ith column of matrix V is ith power of x
  // size of V is length of x
  // ASSUMES each entry of x is distinct for matrix to be full rank
  n = length(x)
  for i = 1:n
      V(:,i) = x^(i-1)
  end
endfunction

// Polynomial least square
a = [1 2 3];
b = [8 7 6];

//--> find coefficients of polynomial that fits b: poly(a)-b 
c = linsolve(vandermode(a),b')


