"Function not found" error in optim package commands

I get this error when using either leasqr or nonlin_curvefit commands, no matter what function I use. Function is always placed before the command.

error: max_nargin_optim: function ‘H’ not found
error: called from
maybe_limit_arg_count at line 28 column 33
nonlin_curvefit at line 61 column 5
DataInhibClav_WE_Mes_fit_ed at line 92 column 20

My system

  • OS: Windows 10 Enterprise 21H2
  • Octave version: 7.3.0
  • Optim: optim 1.6.2 (2022-04-10)
  • Installation method: e.g. Downloaded and installed octave-7.3.0-w64-installer.exe

Works for me with optim 1.6.2:

>> [f, p] = leasqr (1:10, (1:10) + randn(1,10) / 10, [1 1], @(x,p) x*p(1)+p(2))
f =
   1.1281   2.1097   3.0914   4.0731   5.0547   6.0364   7.0181   7.9997   8.9814   9.9631
p =
   0.9817
   0.1464

Pls copy-paste or attach a minimum reproducible example for your error.

1 Like

Thanks for your help! Your command works for me too. The problem seems to be in how I call a predefined function. So the function handle @KK in the test example below must be wrong. In the real script I use a very large, complex function that I cannot add directly in the leasqr command. That’s why I need to call the function name.

time = [1;2;3;4;5];
abs = [5; 5; 5; 5; 5]+randn([5 1])/10;
v = [2; 2];

function S = KK(time, v)
S = time*v(1)+v(2);
endfunction

time
abs
v
U = KK(time, v)

[f, v] = leasqr (time, abs, v, @KK);

f
v

Try this:
[f, v] = leasqr (time, abs, v, @(x) KK(time, x))

Btw it’s best to rename the variable abs since that’s the name of a builtin function.

I had to add both parameters, then it worked:
[f, v] = leasqr (time, absor, v, @(time, v) KK(time, v))
I have changed abs to absor to avoid the predefined ‘abs’.
Thanks a lot for your help!

1 Like