"User supplied objective function must return a scalar value." error using fminbnd
Ältere Kommentare anzeigen
Hello everyone. I am trying to implement the steepest descent algorithm to a convex and nonquadratic function "fun". I need to find the a (alpha) by using fminbnd function in the interval [1,10]. However, I am getting the error "Error using fminbnd: User supplied objective function must return a scalar value." Since xnew and dk matrices also change everytime while loop runs, I could not define the xnew2 function as function handle (I guess, I am not quite sure about the definition of function handle.) I would be glad if someone could help me out with this problem. Thanks a lot.
syms fun(x,y) xnew2(a)
fun(x,y) =(18.*y-0.2.*(x-20).^2).^2 + (20.*x-0.1.*(y-10).^2).^2; %function is defined
g=(gradient(fun,[x,y])); %gradient vector
x0=[0.2 0.2]'; %initial points
xnew=x0; %I don't want to change initial points but I need another variable to start with
iter=0;
dk=-g(xnew(1),xnew(2));
while(norm(dk)>1e-05)
iter=iter+1;
xnew2(a)= xnew+a*dk; %xnew2 is defined with respect to a which as unknown for now
a_new=fminbnd(xnew2,1,10); %a_new will be the local min in the interval 1,10
xnew=xnew+a_new*dk; %xnew will get a new value with the variable
X=['The x vector at iteration ',num2str(iter)];
disp(X)
display(double(xnew));
dk=-g(xnew(1),xnew(2));
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Startup and Shutdown finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!