Functions handles in matlab

326 views Asked by At

i've a problem to understand this snippet of code

output=lsqnonlin(@(argn) fun(arg1,arg2,argn),X0);

My idea is that lsqnonlin will call the argn->fun function recursively,but i'm not sure. is it right?

1

There are 1 answers

1
Itamar Katz On BEST ANSWER

It is impossible to say what lsqnonlin will do without the functions' code. However, there is nothing inherently recursive in the function call in your question.

The 1st argument to lsqnonlin is a function handle, and in the function call in your question, you pass an anonymous function handle:

@(argn) fun(arg1,arg2,argn)

Which is a function with one argument to be used by the function, argn, and two parameters (are pre-set arguments), arg1 and arg2. lsqnonlin uses the function handle you pass it in order to calculate the function value in a specific point or vector of points.

You can read more about anonymous function handle here: http://www.mathworks.com/help/techdoc/matlab_prog/f4-70115.html#f4-70133