As a test I generated an array of values from a quadratic function and then used polyfit to generate coefficients for these values. Polyfit gives me different coefficients than the ones I inputted. Is there any way to fix this? I need to be able to calculate coefficients as accurately as possible from only the first half of the generated values.
My code:
x = linspace(1,100,10000); p = [.0010 0 0]; c = polyval(p,x);
poly1 = polyfit(linspace(1,5000,5000),c(1:5000),2);
f = polyval(fliplr(poly1), x);
plot(x, c);
hold on;
plot(x, f);
Best Answer