## leasqr example/test
global verbose
verbose(1) = 1; verbose (2) = 1;
t = [1:100]';
p = [1; 0.1];
data = leasqrfunc (t, p);
wt1 = (1 + 0 * t) ./ sqrt (data); # = 1 /sqrt of variances of data
if (sscanf (version, "%f") < 4)
  disp ("Used 'rand'");
  rand ("normal");
  data = data + 0.05 * rand (100, 1) ./ wt1;   # 1 / wt1 = sqrt of var = standard deviation
else
  disp ("Used 'randn'");
  data = data + 0.05 * randn (100, 1) ./ wt1;
endif;
options = [[0.01; 0.01], [.8; .8]];
## Note by Thomas Walter <walter@pctc.chemie.uni-erlangen.de>:
##
## Using a step size of 1 to calculate the derivative is WRONG !!!!
## See numerical mathbooks why.
##[f1, p1, kvg1, iter1, corp1, covp1, covr1, stdresid1, Z1, r21] = ...
##    leasqr (t, data, [.8;.05], "leasqrfunc", .001, 50, wt1, [1;1],  "leasqrdfdp", options);
## A derivative calculated from central differences needs:  step = 0.001...1.0e-8
## And a onesided needs:  step = 1.0e-5...1.0e-8 and may be still wrong
[f1, p1, kvg1, iter1, corp1, covp1, covr1, stdresid1, Z1, r21] = ...
    leasqr (t, data, [.8;.05], "leasqrfunc", .001, 50, wt1, [0.001;0.001],  "dfdp", options);
