compute the best fitting (in the sense of least squares method) function of the form f(t)=at2+bt+ct=[3 -1 7 -3 -1 7]f=[5 10 9 10 8 -3]calculate value at −7/2 in matlab

To compute the best fitting function using the least squares method, we can use the polyfit function in MATLAB. The polyfit function fits a polynomial of degree n to the data using least squares method and returns the coefficients of the polynomial in decreasing order of powers.

Here's the MATLAB code to solve the problem:

main.m
f = [3 -1 7 -3 -1 7];
t = [5 10 9 10 8 -3];

% fit a quadratic polynomial (degree 2) to the data
coeff = polyfit(t, f, 2);

% evaluate the polynomial at -7/2
val = polyval(coeff, -7/2);

disp(val); % display the result
219 chars
11 lines

Output:

main.m
-64.6875
9 chars
2 lines

Therefore, the value of the best fitting function at -7/2 is -64.6875.

related categories

gistlibby LogSnag