Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

clc

clear all
f=@(x) (1-((log(1+x^2))/(1+x^2)));
fplot(f,[0.1,5]);
epsilon=1e-10;
a=0.1; d=5;

icount=0;maxIterations=100;
while abs(a-d) > epsilon
icount=icount+1;
%for n=1:10
b=a+(d-a)/3;
c=d-(d-a)/3;
if f(c)<f(b)
a=b;
else
d=c;
end
end

xMin=(a+d)/2;
minVal=f(xMin);

figure
fplot(f,[0.1,5],'-b');
grid on;

hold on;plot(xMin,minVal,'*r');hold off;


title('Minimization through Search')
fprintf('icount= %i \n',icount)
fprintf('Search solution = %8.5f y= %8.5f \n',xMin,minVal)

% MATLAB ROUTINE CALLED: fminsearch

[xsoln,fxsoln]=fminsearch(f,1)
f(xsoln)

% MATLAB ROUTINE CALLED: fminbnd

[xsoln2,fxsoln2]=fminbnd(f,0,1.5)
f(xsoln2)

You might also like