Don't call fminsearch with MyFunc as your objective function from inside MyFunc itself. Move the lines where you call optimset and fminsearch outside MyFunc.
Assuming that MyFunc was nested inside its parent function (so it can "see" the definition of x0) and that parent function called MyFunc with an input x with at least two elements, this would:
- call MyFunc which would call fminsearch which would
- call MyFunc which would call fminsearch which would
- call MyFunc which would call fminsearch ...
Eventually MATLAB would reach the recursion limit and throw an error or it would crash. If you've set the recursion limit too high, it potentially could crash the machine.
0 Comments
Sign in to comment.