<?xml version="1.0" encoding="UTF-8"?>
<Worksheet><Version major="6" minor="1"/><View-Properties><Hide name="Section Range"/><Hide name="Group Range"/><Zoom percentage="100"/></View-Properties><Styles><Layout alignment="centred" firstindent="0.0" leftmargin="0.0" linebreak="space" linespacing="0.0" name="Author" rightmargin="0.0" spaceabove="8.0" spacebelow="8.0"/><Layout alignment="left" firstindent="0.0" leftmargin="0.0" linebreak="space" linespacing="0.0" name="Heading 1" rightmargin="0.0" spaceabove="8.0" spacebelow="4.0"/><Layout alignment="left" firstindent="0.0" leftmargin="0.0" linebreak="space" linespacing="0.0" name="Normal" rightmargin="0.0" spaceabove="0.0" spacebelow="0.0"/><Layout alignment="centred" firstindent="0.0" leftmargin="0.0" linebreak="space" linespacing="0.0" name="Normal256" rightmargin="0.0" spaceabove="0.0" spacebelow="0.0"/><Layout alignment="centred" firstindent="0.0" leftmargin="0.0" linebreak="space" linespacing="0.0" name="Title" rightmargin="0.0" spaceabove="12.0" spacebelow="12.0"/><Font background="[0,0,0]" italic="true" name="_cstyle288"/><Font background="[0,0,0]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" name="Heading 1" readonly="false" size="18" underline="false"/><Font background="[0,0,0]" italic="true" name="_cstyle287"/><Font background="[0,0,0]" italic="true" name="_cstyle286"/><Font background="[0,0,0]" italic="true" name="_cstyle285"/><Font background="[0,0,0]" bold="true" executable="true" family="Monospaced" foreground="[255,0,0]" name="Maple Input"/><Font background="[0,0,0]" bold="true" name="_cstyle284"/><Font background="[0,0,0]" bold="true" name="_cstyle283"/><Font background="[0,0,0]" italic="true" name="_cstyle282"/><Font background="[0,0,0]" family="Times New Roman" name="Page Number" underline="false"/><Font background="[0,0,0]" bold="true" name="_cstyle281"/><Font background="[0,0,0]" italic="true" name="_cstyle280"/><Font background="[0,0,0]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" name="Normal" readonly="false" size="12" underline="false"/><Font background="[0,0,0]" bold="true" name="_cstyle279"/><Font background="[0,0,0]" bold="true" name="_cstyle278"/><Font background="[0,0,0]" bold="true" name="_cstyle277"/><Font background="[0,0,0]" bold="true" name="_cstyle276"/><Font background="[0,0,0]" bold="true" name="_cstyle275"/><Font background="[0,0,0]" bold="true" name="_cstyle274"/><Font background="[0,0,0]" bold="true" name="_cstyle273"/><Font background="[0,0,0]" bold="true" name="_cstyle272"/><Font background="[0,0,0]" bold="true" name="_cstyle271"/><Font background="[0,0,0]" bold="true" name="_cstyle270"/><Font background="[0,0,0]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" name="Author" readonly="false" size="12" underline="false"/><Font background="[0,0,0]" italic="true" name="_cstyle269"/><Font background="[0,0,0]" italic="true" name="_cstyle268"/><Font background="[0,0,0]" italic="true" name="_cstyle267"/><Font background="[0,0,0]" italic="true" name="_cstyle266"/><Font background="[0,0,0]" italic="true" name="_cstyle265"/><Font background="[0,0,0]" italic="true" name="_cstyle264"/><Font background="[0,0,0]" italic="true" name="_cstyle263"/><Font background="[0,0,0]" italic="true" name="_cstyle262"/><Font background="[0,0,0]" italic="true" name="_cstyle261"/><Font background="[0,0,0]" italic="true" name="_cstyle260" underline="true"/><Font background="[0,0,0]" bold="false" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" name="Normal256" readonly="false" size="24" underline="false"/><Font background="[0,0,0]" italic="true" name="_cstyle259"/><Font background="[0,0,0]" italic="true" name="_cstyle258" underline="true"/><Font background="[0,0,0]" italic="true" name="_cstyle257"/><Font background="[0,0,0]" family="Times New Roman" name="2D Comment" underline="false"/><Font background="[0,0,0]" bold="true" executable="false" family="Times New Roman" foreground="[0,0,0]" italic="false" name="Title" readonly="false" size="18" underline="true"/></Styles><Page-Numbers enabled="false" first-number="1" first-numbered-page="1" horizontal-location="right" style="Page Number" vertical-location="bottom"/><Group><Input><Text-field layout="Title" style="Title">Fibonacci Search in Optimization of Unimodal Functions</Text-field><Text-field layout="Author" style="Author">by Dr. William P. Fox, Department of Mathematics  
Francis Marion University, Florence, SC 29501, wfox@fmarion.edu
(c) 2002 William P. Fox</Text-field></Input></Group><Group><Input><Text-field layout="Normal256" style="Normal256"/><Text-field layout="Normal" style="Normal">This program performs the Fibonacci  Line Search algorithm to find the maximum of a unimodal function, <Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle262" underline="false">f(x)</Font>, over an interval,<Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle257" underline="false"> a</Font><Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle258">&lt;</Font><Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle259" underline="false"> x </Font><Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle260">&lt;</Font><Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle261" underline="false"> b</Font>. The program calculates the number of iterations required  to insure the final interval is within the <Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle263" underline="false">user-specified</Font> tolerance. This is found by solving for the smallest value of n that makes this inequality true: Fn &gt;(b-a)/tolerance, where n is the Fibonacci number from the sequence {F0,F1, F2, ...}.  The Fibonacci search concept involves placing two experiments between [a,b] using the ratios of Fibonacci numbers. (The limit of the ratio of Fibonacci numbers is the golden section 0.618 but the Fibonacci method converges quicker.) One experiment is placed at position,  <Equation input-equation="a+F(n-k-2)/F(n-k) *(b-a)" style="2D Comment">NiMsJiUiYUciIiIqKC0lIkZHNiMsKCUibkdGJSUia0chIiIiIiNGLUYlLUYoNiMsJkYrRiVGLEYtRi0sJiUiYkdGJUYkRi1GJUYl</Equation>, and the other at position,  <Equation input-equation="a+F(n-k-1)/F(n-k) *(b-a)" style="2D Comment">NiMsJiUiYUciIiIqKC0lIkZHNiMsKCUibkdGJSUia0chIiJGJUYtRiUtRig2IywmRitGJUYsRi1GLSwmJSJiR0YlRiRGLUYlRiU=</Equation>. The function, to be maximized, is evaluated at these two points and the functional values are compared. We want to keep the larger functional value (in our maximization problem) and its corresponding opposite end -point. At the end of the required iterations, the final interval is the answer. At times when the final answer must be a single point and not an interval, the convention of selecting the midpoint is provided. This program works when the function is not differentiable and we are looking for a solution. If you need to minimize a function, then multiple the function by (-1) and find the maximum. </Text-field><Text-field layout="Normal" style="Normal"/><Text-field layout="Normal" style="Normal">To find a maximum solution to given a function, f(x), on the interval [a, b] where the function, f(x),  is unimodal.</Text-field></Input></Group><Section collapsed="true"><Title><Text-field layout="Heading 1" style="Heading 1">Overview of the algorithm</Text-field></Title><Group><Input><Text-field layout="Normal" style="Normal"><Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" style="_cstyle270" underline="false">INPUT</Font>:	endpoints a, b; tolerance, t, Fibonacci sequence<Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" style="_cstyle271" underline="false">
OUTPUT</Font>:	final interval [ai, bi], f(midpoint)<Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" style="_cstyle272" underline="false">
Step 1</Font>.  	Initialize the tolerance, t &gt;0.<Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" style="_cstyle273" underline="false">
Step 2</Font>.	Set Fn &gt; (b-a)/t as the smallest Fn and define the test points
	<Equation input-equation="x1 = a+(Fn-2/Fn)*(b-a);" style="2D Comment">NiMvJSN4MUcsJiUiYUciIiIqJiwmJSNGbkdGJyomIiIjRidGKiEiIkYtRicsJiUiYkdGJ0YmRi1GJ0Yn</Equation>
	<Equation input-equation="x2 = a+(Fn-1/Fn)*b;" style="2D Comment">NiMvJSN4MkcsJiUiYUciIiIqJiwmJSNGbkdGJyomRidGJ0YqISIiRixGJyUiYkdGJ0Yn</Equation><Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" style="_cstyle274" underline="false">
Step 3</Font>.	Calculate f(x1) and f(x2)<Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" style="_cstyle275" underline="false">
Step 4</Font>.	Compare f(x1) and f(x2)
(a.) If f(x1) &lt; f(x2), then the new interval is [x1, b]:
	       		a becomes the previous x1
	       		b  does not change
	       		x1 becomes the previous x2
          n = n-1
			Find the new x2 using the formula in Step 2.
(b.) If f(x1) &gt; f(x2),  then the new interval is [a, x2]:
	       		a  does not change
	       		b becomes the previous x2
	       		x2 becomes the previous x1
          n = n-1
			Find the new x1 using the formula in Step 2.<Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" style="_cstyle276" underline="false">
Step 5</Font>. 	If the length of the new interval from Step 4 is less than the tolerance specified, the stop. Otherwise go back to Step 3.<Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" style="_cstyle277" underline="false">
Step 6</Font>. 	Estimate x* as the midpoint of the final interval and compute, f(x*), the estimated maximum of the function.<Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" style="_cstyle278" underline="false">
STOP</Font>
</Text-field><Text-field layout="Normal" style="Normal">To utilize the Fibonacci routine you need the following:</Text-field><Text-field layout="Normal" style="Normal">User inputs are:</Text-field><Text-field layout="Normal" style="Normal">    The user enters the function <Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle264" underline="false">f</Font> using</Text-field><Text-field layout="Normal" style="_cstyle265"><Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" underline="false">f:=x-&gt;&lt;enter the expression in x&gt;</Font></Text-field><Text-field layout="Normal" style="Normal">Type <Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle266" underline="false">FIBSearch(f, a, b, tolerance) </Font>for specific values of <Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle267" underline="false">a, b,</Font> and the <Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle268" underline="false">tolerance</Font>.</Text-field><Text-field layout="Normal" style="Normal">The output is the iterative process (each step).</Text-field><Text-field layout="Normal" style="Normal">The last output provided is the midpoint of the final interval and the value of <Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle269" underline="false">f(x) </Font>at that point.</Text-field></Input></Group></Section><Section collapsed="true"><Title><Text-field layout="Heading 1" style="Heading 1">Program Code</Text-field></Title><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">FIBSearch:=proc(f::procedure,a::numeric,b::numeric,T::numeric)
local L, M, j, C, x1, x2, N, val;
L:=(b-a)/T;
M:=round(L);
j:=0;
label_2;
C:=fib(j);
if C&lt;L then
j:=j+1;
goto(label_2);
else
N:=j;
end if;
x1:=evalf(a+(fib(N-2)/fib(N))*(b-a));
x2:=evalf(a+(fib(N-1)/fib(N))*(b-a));
printf("The interval [a,b] is [% 4.2f,% 4.2f]and user specified tolerance level is% 6.5f.\n",a,b,T);
### WARNING: %x or %X format should be %y or %Y if used with floating point argumentsprintf("The first 2 experimental endpoints are x1= % 6.3f and x2 = % 6.3f. \n",x1,x2);
printf(" \n");
printf("  \n");

printf(" Iteration    x(1)       x(2)      f(x1)      f(x2)           Interval \n");
iterate(f,a,b,N,x1,x2);

val:=f(mdpt);
printf("  \n");
printf("  \n");
printf("The midpoint of the final interval is% 9.6f and f(midpoint) = % 7.3f. \n",mdpt, val);
printf("  \n");
printf("  \n");
### WARNING: %x or %X format should be %y or %Y if used with floating point arguments
printf("The maximum of the function is % 7.3f and the x value = % 9.6f \n",fkeep,xkeep);
printf("  \n");
printf("  \n");
end:
iterate:=proc(f::procedure,a::numeric,b::numeric, N::posint,x1::numeric,x2::numeric)
local x1n,x2n,an,bn,i,fx1,fx2,j,f1,f2,fmid;
global mdpt,fkeep,xkeep,fib;
i:=1;
x1n(1):=x1;
x2n(1):=x2;
an(1):=a;
bn(1):=b;
i:=1;
for j from 1 to N do
fx1(i):=evalf(f(x1n(i)));
fx2(i):=evalf(f(x2n(i)));
if fx1(i)&lt;=fx2(i) then
an(i+1):=x1n(i);
bn(i+1):=bn(i);
x1n(i+1):=x2n(i);
x2n(i+1):=an(i+1)+(fib(N-i-1)/fib(N-i))*(bn(i+1)-an(i+1));
else
an(i+1):=an(i);
bn(i+1):=x2n(i);
x2n(i+1):=x1n(i);
x1n(i+1):=an(i+1)+(fib(N-i-2)/fib(N-i))*(bn(i+1)-an(i+1));
fi;
i:=i+1;

printf("   % 3.0f % 11.4f % 10.4f % 10.4f %10.4f     [% 6.4f, % 6.4f]\n",i,x1n(i),x2n(i),fx1(i-1),fx2(i-1),an(i),bn(i));
mdpt := (an(i) + bn(i))/2;


if ((i+2)=N) then
if evalf(f(an(i))) &gt; evalf(f(bn(i))) or evalf(f(an(i))) &gt; evalf(f(mdpt)) then 
    fkeep := f(an(i)); xkeep := an(i);
 else
   if evalf(f(bn(i))) &gt; evalf(f(mdpt)) then
    fkeep := f(bn(i)); xkeep := bn(i);
   else
    fkeep := f(mdpt); xkeep := mdpt;
end if;
end if;
end if;
if(N-i-2)&lt;0 then: goto(label_3):end if;
end do;
label_3;
end:</Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">fib:=proc(n::numeric)
option rememer;
fib(0):=1:fib(1):=1;
if n&lt;2 then
n;
else
fib(n-1)+fib(n-2);
end if;
end:</Font></Text-field></Input></Group></Section><Section collapsed="true"><Title><Text-field layout="Heading 1" style="Heading 1">Examples</Text-field></Title><Group><Input><Text-field layout="Normal" style="_cstyle279"><Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" underline="false">Example 1</Font></Text-field><Text-field layout="Normal" style="Normal">Maximize the function <Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle280" underline="false">f(x)=-x^2+21.6*x+3 </Font>over the interval [0,20]<Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle286" underline="false">.</Font>. Via calculus the maximum is at 10.8. Let's see how the Fibonacci Search does.</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">f:= x-&gt;-x^2+21.6*x+3;</Font></Text-field><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">FIBSearch(f,0,20,.001);</Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="_cstyle281"><Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" underline="false">Example 2 </Font></Text-field><Text-field layout="Normal" style="Normal">Maximize a function whose derivative can not be solved explictly for 0.</Text-field><Text-field layout="Normal" style="Normal">Maximize the function, <Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle282" underline="false">f(x) = x-exp(x)</Font> over the interval [-1,3].</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">f:= x-&gt;x^2-exp(x);</Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">FIBSearch(f,0,3,.1);</Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="_cstyle283"><Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" underline="false">Example 3.</Font></Text-field><Text-field layout="Normal" style="Normal">Maximizing a function that does not have a derivative.</Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">f:= x-&gt;-(abs(2-x)+abs(5-4*x)+abs(8-9*x));</Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">FIBSearch(f,0,3,.1);</Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" style="_cstyle284"><Font family="Times New Roman" foreground="[0,0,0]" italic="false" size="12" underline="false">Example 5.</Font></Text-field><Text-field layout="Normal" style="Normal">Minimize the function, <Equation input-equation="2x^2-4*x" style="2D Comment">NiMsJiomIiIjIiIiKiQlInhHRiVGJkYmKiYiIiVGJkYoRiYhIiI=</Equation><Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle285" underline="false">. </Font>To minimize <Equation input-equation="f(x)" style="2D Comment">NiMtJSJmRzYjJSJ4Rw==</Equation><Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle288" underline="false">, </Font> we maximize <Equation input-equation="-f(x)= -2 x^2+4*x" style="2D Comment">NiMvLCQtJSJmRzYjJSJ4RyEiIiwmKiYiIiMiIiIqJEYoRixGLUYpKiYiIiVGLUYoRi1GLQ==</Equation><Font bold="false" family="Times New Roman" foreground="[0,0,0]" size="12" style="_cstyle287" underline="false">. </Font>We keep the interval the same.</Text-field><Text-field layout="Normal" style="Normal"/></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">f:= x-&gt;-2*x^2+4*x;</Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">FIBSearch(f,-1,2,.1);</Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">f:=(x)-&gt;1-exp(-x)+1/(1+x); </Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"><Font italic="false" size="12" underline="false">FIBSearch(f,0,20,.1);  </Font></Text-field></Input></Group><Group><Input><Text-field layout="Normal" prompt="&gt; " style="Maple Input"/></Input></Group></Section><Text-field/></Worksheet>