I am trying to minimize with respect to a variable "y" a function that contains a parameter which must be calculated as a solution of an equality that contains "y" as well (say, y=-3; in my complete problem it is an equation with no analytic closed form solution, so I really need fzero). Because of this, I include the fzero function in the argument of fminsearch:
fminsearch( @(y) 10*fzero(@(y) y+3, 0)) ;
I get the error:
Error using fminsearch (line 85)
The input to FMINSEARCH should be either a structure with
valid fields or consist of at least two arguments.
I obviously get the same error with: f = fzero(@(y) y+3, 0); fminsearch(@(y) 10*f);
Apparently the problem is that I cannot "nest" a fzero inside fminsearch. Any idea about how to turn around this problem?
If you read the error message you got and look at the documentation of fminsearch
you'll see that you need to call it with two input arguments. You call it with only one.
fminsearch( @(y) 10*fzero(@(x) x+3, 0), 0 )