MatrixLLS question

Hello,

I'm currently using the MatrixLLS command to solve for coefficients which fit a basis set expansion to data. My "matrixA" is my matrix of basis sets and my "matrixB" is my data. My basis sets are a set of step functions, the sum of my coefficients multiplied by my basis returns the fit. I've tested this program in an idealized situation where my matrixB is a Gaussian and the fit looks great and the distribution of coefficients makes sense.

Where I'm running into trouble is when I try to fit real data. The resulting fit of course looks great, but the coefficients don't really make sense -- I'd like all of them to be either positive or 0 instead of returning some negative numbers mixed with positive numbers. Is there a way require the output coefficients to be all positive numbers?

Thank you!
That is one way of going about fitting a dataset. The other way is by using the Funcfit (Levenberg Marquardt) or Gencurvefit (differential evolution) operations, together with a fit function, to fit your dataset. The fitfunction looks something like this:

Function myfitfunc(w, yy, xx):fitfunc
Wave w, yy, xx
End


Here w is a wave containing your model coefficients that are used together with a wave containing the independent variables (xx) to populate a wave containing the model dependent variable, yy. When you use this approach it's easy to specify that all your coefficients must be positive, you can also set upper bounds. You can use different lengths of the coefficient wave to use more terms of your basis function. I have used such an approach with the Chebyshev polynomial basis set.
You can even use different cost functions (e.g. minimise sum of absolute residuals).