MATLAB: Alternates of polyval and polyfit

polyfitpolyval

I'm working on an assignment that has to do with interpolating polynomials where I create a picture reading in the data points from a file. However, I am not allowed to use the functions polyfit or polyval. How would I go about finding the coefficients of a polynomial and generating a curve based on those coefficients?

Best Answer

Suppose you had a polynomial of degree 2, y = a2*x^2 + a1*x^1 + a0*x^0, a2, a1, a0 unknown then you can write that as
[x^2, x^1, x^0] * [a2; a1; a0] = y
Now fill in those values as columns for all known x, y
A = [x1^2, x1, 1
x2^2, x2, 1
x3^2, x3, 1
...]
b = [y1;
y2
y3
...]
and then it follows that
A * [a2; a1; a0] = b
which is a (possibly overdetermined) system of simultaneous linear equations you can solve by your favorite method