fminbnd supplies anonymous function with a vector rather than a scalar

My M-file function Y = MEP_ObjFun(P,B,R,T) requires inputs scalar P and [1 x N] vectors B, R, T and returns a scalar Y.
When I call this anonymously using fminbnd()
Popt = fminbnd(@(y)MEP_ObjFun(y,B,R,T),lb,ub);
and inquire size(P) inside of MEP_ObjFun.m it returns [1 x N].
Why is fminbnd assuming I want to pass a vector rather than a scalar and how do I control this?
Thank you, Grey

4 Comments

Any chance you overwrite P in MEP_ObjFun?
P is not overwritten in the function, which is reporduced below.
function Y = MEP_ObjFun(P,B,R,T)
size(P)
G = 11*P*R./((12*B)-P);
Phat = P_from_G(G,T);
Y = (P-Phat)^2;
end
I just tried the same syntax for FMINBND as above and the value for P was always a scalar. Make sure that you are calling the correct function:
which -all fminbnd

Sign in to comment.

 Accepted Answer

Problem: One (or both) of the bounds (lb, ub) is a vector.

More Answers (0)

Categories

Find more on Code Generation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!