function testing
z0 = [5 6];
parameters = 8;
options = optimset('Display','iter','MaxFunEvals',100);
z = fminbnd(@(z0) mryk(z0,parameters),5,7,options);
display(z);
end
%--------------------------------------------------------------------------
function h = mryk(x,param)
h = 2*x(1)^2+x(2)^2+param;
end
cheers
What is wrong? fminbnd is a SINGLE variable optimizer.
Use a tool that can optimize problems with more than
one unknown. So use either a tool from the optimization
toolbox (fmincon) or my own fminsearchbnd, found on
the File Exchange.
http://www.mathworks.com/matlabcentral/fileexchange/8277
John
FMINBND is only applicable to single-variable problems.
fminbnd is for single-variable functions.
Use fminsearch or fmincon instead.
Best wishes
Torsten.
There is no x0 in the code that you've shown. Possibly you meant z0, but z0 never gets passed to fmincon. Note that the z0 in this expression
@(z0) mryk(z0,parameters)
has nothing to do with z0=[5,6].
>
> function h = mryk(x,param)
>
> h = 2*x(1)^2+x(2)^2+param;
> end
======
Possibly, your code was just a simplified example (if so, I don't see why you threw "param" in there - it doesn't affect the optimization at all).
In any case, your function mryk is additively separable, meaning you can minimize over each variable x(1) and x(2) separately. To do so, you could use fminbnd, although in this instance it's also pretty easy to do the minimization analytically.
Ta! Just one more issue. I have noticed it does not work with the anonymous function in form:
z = fminsearchbnd(@(z0) mryk(z0,para),[5 6],[12 14],options);
is there an alternative to pass 'para' without resolving to global variables? just adding para at the end after options only seems to confuse Matlab, not to mention I have got a lot of additional parameters to pass.
cheers
Maybe the reason is that you also gave the name
(z0) to the initial vector ...
Best wishes
Torsten.
It DOES work with an anonymous function.
However, read the help. The second argument is
NOT the lower bound, it IS the starting value
for the optimization.
Had you tried this...
z = fminsearchbnd(@(z0) mryk(z0,para),[8 10],[5 6],[12 14],options);
It should have worked significantly better.
John
THANKS! Sorry for the 'RTFM' question, I read it but apparently not carefully. Ta!