Well, actually, this problem can be solve quite trivially in a way that does not require lsqlin, or anything fancy. There really is no requirement for a linear constraint, since the constraint will be that the constant parameter in the polynomial model is just zero. So use backslash to estimate the model coefficients, and just leave out the constant term. Note that this works ONLY to force a point through the origin, since the point (x,y) = (0,0) in a polynomial model implies that the constant term MUST be identically zero.
So, given a model of the form
y = a1*x^3 + a*x^2 + a3*x
we can fit it simply as
a123 = [x.^3, x.^2, x]\y;
where x and y are column vectors of data.
You can even use polyval to evaluate the polynomial, simply by appending a zero to the end of that vector f coefficients, thus
If you wanted to force the mode to pass through the point (x0,y0), where these values are not the origin, then we need to work slightly more, but not a lot. While you can do so with lsqlin, if you don't have that tool (or my own LSE, as found on the file exchange) just do this simple transformation:
xtr = x - x0;
a123 = [xtr.^3, xtr.^2, xtr]\(y - y0);
Essentially, we have now fit the model
y - y0 = a1*(x - x0)^3 + a*(x - x0)^2 + a3*(x - x0)
You can see that when x == x0, y must be predicted as y0.
Evaluation of this model is just as easy. You can still use polyval, just remember to subtract off x0 from x first.
P = [a123;y0];
ypred = polyval(P,xpred - x0);
What happens when we have a more complicated problem, where maybe you need to force TWO points on the curve? Well, then, you can use either lsqlin or my own LSE. (Note that LSE runs in R2015a with no warning messages.)
Or, if you have a trigonometric model? If the model has nonlinear parameters in it, then you will need to use a nonlinear optimization. And depending on the model, to force it through a given point, that may require a nonlinear tool that can handle an equality constraint, so possibly fmincon. But sometimes, again, depending on the model, there may be simpler solutions. It all depends on the model.