clear all close all %1-d example of fminsearch using the function "quartic" xp=0:.001:4; figure(1) plot(xp,quartic(xp)) % fminsearch outputs the value at which your function hits % a local minima % use syntax @(variablename) funcall(variablename) % note the two variablename must match % second component is initial guess guess=1.96 bottom1=fminsearch(@(xp) quartic(xp),guess) hold on plot(guess,quartic(guess),'g*',bottom1,quartic(bottom1),'r*') %2-d example using function "myfun" %x=[-1:.1:1; -1:.1:1].'; %n=length(x); %for i=1:n % z(i)=myfun(x(i,:)); %end %figure(2) %plot3(x(:,1),x(:,2),z) %bottom2=fminsearch(@(x) myfun(x), [1 1]) %hold on %plot3(1,1,myfun([1 1]),'g*',bottom2(1),bottom2(2),myfun(bottom2),'r*')