Nonlinear fits in Octave

P. Scwurf

currently I'm using nonlin_curvefit function from GNU Octave's 'optim' package to fit data with . But this time I did also need the uncertainty of the returned parameters to determine the quality of the fit. After reading through the documentation I tied using the function curvefit_stat. However whenever I alwas get errors using this functiona and I can't make any sense of the error message. I'm using Octave 4.2.2 from Ubuntu 18.04's default repository.

Standalone minimal example and error messages below. Startparameters init_cvg usually produces good result, while using init_dvg usually results in poor fits:

1;

x = linspace(-2*pi, 2*pi, 600);
ydata = 3.4*sin(1.6*x) + rand(size(x))*1.3;

f = @(p, x) p(1)*sin(p(2).*x);
function y  = testfun(p ,x)
  y = p(1).*sin(p(2).*x);
endfunction

init_cvg = [1; 1.1];
init_dvg = [1; 1.0];

[pc, mod_valc, cvgc, outpc] = nonlin_curvefit(f, init_cvg, x, ydata);
[pd, mod_vald, cvgd, outpd] = nonlin_curvefit(f, init_dvg, x, ydata);


hold off
plot(x, yd, "b.");
hold on;
plot(x, mod_valc, "r-");
plot(x, mod_vald, "color", [0.9 0.4 0.3]);

settings = optimset("ret_covp", true);
covpc = curvefit_stat(f, pc, x, ydata, settings);
covpd = curvefit_stat(f, pd, x, ydata, settings);

puts("sqrt(diag(covpc))")
sqrt(diag(covpc))

puts("sqrt(diag(covpd))")
sqrt(diag(covpd))

The first error message occurs when I use f as a model function, the second occurs when I use testfun instead:

>> curvefit_stat_TEST
error: label of objective function must be specified
error: called from
    __residmin_stat__ at line 566 column 7
    curvefit_stat at line 56 column 7
    curvefit_stat_TEST at line 25 column 7
>> curvefit_stat_TEST
error: 'p' undefined near line 8 column 7
error: called from
    testfun at line 8 column 5
    curvefit_stat_TEST at line 25 column 7
>>

Could somebody confirm this error ?

I would appreciate any help.

P. Scwurf

I found the problem. I needed to add "abjf_type", "wls" as arguments to optimset.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related