quadratic_fit_test.m 251 B

1234567891011121314
  1. t = [0 1 2 3 4 5];
  2. x = [1.1 4.4 11.2 20.3 33.1 48.6];
  3. t = t';
  4. x = x';
  5. A = [t.^2 t ones(6,1)]
  6. p = A\x;
  7. t_fitted = linspace(min(t), max(t), 100);
  8. x_fitted = p(1)*t_fitted.^2 + p(2)*t_fitted + p(3);
  9. hold on;
  10. plot(t_fitted, x_fitted);
  11. plot(t, x, 'ro');