Hello everybody
I would like to store the result of each iteration of the Fibonacci search algorithm.
if true function x=fibosearch(fhandle,a,b,npoints)x = [-50:10:20];a1 = 0.2661; b1 = -18.24; c1 = 21.62; a2 = 1.135e+09; b2 = 1.174e+04; c2 = 2555;fhandle = @(x)a1*exp(-((x-b1)/c1).^2) + a2*exp(-((x-b2)/c2).^2);a=-50;b=20;npoints=100;nfibo=22;fibo=[1,1,zeros(1,nfibo-2)];for k=1:nfibo-2 fibo(k+2)=fibo(k+1)+fibo(k);endfiboindex=3;while fibo(fiboindex)<npoints fiboindex=fiboindex+1;endfor k=1:fiboindex-2 if k==1 x1 = a+fibo(fiboindex-k-1)/fibo(fiboindex-k+1)*(b-a); x2 = b-fibo(fiboindex-k-1)/fibo(fiboindex-k+1)*(b-a); fx1 = fhandle(x1); fx2 = fhandle(x2); endif fx1<fx2 a=x1; x1=x2; fx1=fx2; x2=b-fibo(fiboindex-k-1)/fibo(fiboindex-k+1)*(b-a); fx2=fhandle(x2); else b=x2; x2=x1; fx2=fx1; x1=a+fibo(fiboindex-k-1)/fibo(fiboindex-k+1)*(b-a); fx1=fhandle(x1);endendif fx1<fx2 x=x2;else x=x1;enddisp(fiboindex-2) endend
The result of the final iteration is -16.0501624147 which is x. However, I would like to see the result of each iteration. How can I plot iteration number vs result of iteration?
Any help is highly appreciated.
Thanks
Best Answer