calling a function with lsqnonlin

I'm attempting to call minimize the value of a function (chi2) using lsqnonlin as shown below
[fitpar,resnorm01,residual]=lsqnonlin(chi2,inpar,lb,ub,options);
the chi2 function works, but i get the following error ??? Error using ==> lsqfcnchk at 111 FUN must be a function, a valid string expression, or an inline function object.
it works when using the function handle @ (as shown below) [fitpar,resnorm01,residual]=lsqnonlin(@chi2,inpar,lb,ub,options);
but when I use the function handle i can't provide additional inputs to the function, i.e. @chi2(x,y,z) which would greatly simplify things downstream. Any advice?

回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 3 月 8 日

0 投票

@(x,y,z)chi2(x,y,z)
You need to explictly declare the inputs. If there are none, leave it empty:
@()chi2(x,y,z)
For more info:
doc function_handle

1 件のコメント

Sulakshan Arya
Sulakshan Arya 2014 年 7 月 6 日
I am using fsolve command to solve nonlinear equation through Simulink MATLAB function.
If i use fsolve(@myfun,x0) i get Error using ==> "function handles are unsupported for MATLAB calls", and if i use fsolve(myfun,x0) i get Error using ==> lsqfcnchk at 111 FUN must be a function, a valid string expression, or an inline function object.
Any solution???

サインインしてコメントする。

製品

質問済み:

Dan
2012 年 3 月 8 日

コメント済み:

2014 年 7 月 6 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by