MATLAB: Given an equation and data points, find the best fit coefficients of the equation

best fitdata pointsdata setfinding coefficients

If I am given a set of x and y data points and I have to find the best fit curve for those points polynomial) I know to use the polyfit function.
However, If I am now given an equation and need to find that equations coefficients how would I go about doing that?
The equation can be found below:
tg^-1 is tan^-1 which I know in Matlab is atan(x)
I need to find B, C, D, and E in the above equation given my set of data points.

Best Answer

Over the short term, you could open cftool from the Curve Fitting Toolbox, select your input variables, then on the right hand side ask for a custom equation.
Over the longer term (code), you would use https://www.mathworks.com/help/curvefit/fittype.html fittype() to pass in an anonymous function and describe it in terms of independent variables and so on. Then you would https://www.mathworks.com/help/curvefit/fit.html fit() passing in that fittype object and the data, and possibly some options (such as upper and lower bounds.) The result would be a cfit object. You can then query the object such as by looking at its coeffs property.