To compute the best fitting function of the form f(t) = a/t + b in the sense of least squares method, we can use the polyfit function in MATLAB. Here's the code:
main.m140 chars6 lines
This code first constructs the new variable 1/t, and then fits a linear function to it using polyfit. The coeffs
variable contains the coefficients of the linear function, with the first element being the coefficient of a/t and the second element being the coefficient of b. We can then evaluate the function at -2 using the formula:
main.m21 chars2 lines
And here's the complete code:
main.m193 chars8 lines
So the value of the best fitting function at -2 is approximately -1.8342.
gistlibby LogSnag