[Scilab-users] Fitting correlations to measured data. Write-ups of leastsq is messy ...
Scilab is a great and powerful mathematical tool that can be used for fitting correlations to measured data.
For me, the help functions and literature write-ups for least-squares fitting in Scilab were tedious and I found them difficult to follow.
At an elementary level, I have sorted out my problems. I would like to report on it, but I am grateful for any further suggestions.
First: linear least-squares fitting: with measurement data x=[2 7 12]'; y=[2 4.5 6.5]';
it is easy, to fit a straight line and plot it:
M=[ones(x) x]; a=M\y; plot2d(x,M*a); plot(x,y,'r.');
Strangely, you find the recipe under "backslash" and this is not very straightforward. The method is really neat, because you can easily fit a polynomial of 25th order or any correlation that is linear in the parameters.
Correlations not linear in the parameters need non-linear least-squares fitting, e.g. with "leastsq", where the Scilab help function is terribly complex.
In my case, I wanted to simultaneously fit three straight lines through three measurement series with the condition that all 3 lines start at the same point on the x-axis. So the following worked well for me: