compute the best fitting (in the sense of least squares method) function of the form f(t)=a/t+b for the data below. tf16−13−5−3−449−3−97 then its value at −7 is in matlab

To find the best fitting function of the form f(t) = a/t + b, we need to perform a linear regression of the data on the variables 1/t and 1. This is because the model is not linear in the coefficients a and b, but it is linear in 1/t and 1.

Here's how to do it in Matlab:

main.m
% Data
t = [-16 -13 -5 -3 -4 9 -3 -9];
f = [3 -1 -3 46 9 -8 -7 11];

% Linear regression
X = [1./t' ones(size(t'))];   % Design matrix
b = X\f';                     % Coefficient estimates (backslash is for solving linear systems)
a = b(1);
b = b(2);

% Evaluate at -7
t_val = -7;
f_val = a/t_val + b;
302 chars
14 lines

The values of a and b will give you the coefficients of the best fitting function, and f_val will give you its value at -7.

gistlibby LogSnag