compute the best fitting (in the sense of least squares method) function of the form f(t)=at+btf−7−310−710−489−5−91−59−2 then its value at −10 is in matlab

We can use the polyfit function in MATLAB to find the best-fitting function of the given form using the least-squares method. We will also use polyval function to evaluate the function at -10.

Here's an example code:

main.m
t = [-3,-1,0,1,2,5,7]; % the x values
y = [-3,1,-1,2,5,7,9]; % the y values

% find the coefficients of the best-fitting polynomial of degree 1
p = polyfit(t, y, 1);

% evaluate the polynomial at -10
result = polyval(p, -10);
226 chars
9 lines

In your case, we will just replace the t and y vectors with the data points from the given function.

main.m
t = [-7,-3,-1,0,4,8,9];
y = [-310,-710,-489,-5,-9,-1,-59];

% find the coefficients of the best-fitting polynomial of degree 1
p = polyfit(t, y, 1);

% evaluate the polynomial at -10
result = polyval(p, -10);
209 chars
9 lines

The value of the best-fitting function at -10 is stored in the variable result.

gistlibby LogSnag