[Date Index]
[Thread Index]
[Author Index]
Re: Understanding Fibonacci Search
*To*: mathgroup at smc.vnet.net
*Subject*: [mg45423] Re: Understanding Fibonacci Search
*From*: poujadej at yahoo.fr (Jean-Claude Poujade)
*Date*: Wed, 7 Jan 2004 01:09:16 -0500 (EST)
*References*: <btdus8$e4$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
adurstew at yahoo.com (Andrew J Durstewitz) wrote in message news:<btdus8$e4$1 at smc.vnet.net>...
> Hi!
>
> As a pretense, I'm a programmer trying to understand practicle use of
> the Fibonacci search.
>
> What I am trying to understand is how exactly to use the following
> equation for intializing the Fibonacci search.
>
> Let x=a+(1-g_n)(b-a) and y=a+g_N(b-a)
>
> Evaluate f(x) and f(y) and set n=N
>
> Here's my delima, I don't understand where those variables come from
> or how to assign them.
>
> I appoligize for my ignorance with this situation but I'm trying to
> learn more.
>
> Thank you for any assistance you can provide.
> Andrew J Durstewitz
A friend of mine handed me this example :
FibonacciMaximum[f_(* function *),
x_(* variable *),
a0_(* left end *),
b0_(* right end *),
t_(* tolerance *)]:=
Module[{a=a0, b=b0, n, x1, x2, f1, f2},
(* compute n = number of iterations : *)
For[i=0, Fibonacci[i+1] < (b-a)/t, i++]; n=i;
x1 = a+(Fibonacci[n-2+1]/Fibonacci[n+1])(b-a);
x2 = b-(Fibonacci[n-2+1]/Fibonacci[n+1])(b-a);
Do[
f1 = f /. x -> x1;
f2 = f /. x -> x2;
(* compute new interval [a, b] : *)
If[f1 >= f2,
b=x2;
x2=x1;
x1=a+(Fibonacci[n-k-2+1]/Fibonacci[n-k+1])(b-a),
(* else *)
a=x1;
x1=x2;
x2=b-(Fibonacci[n-k-2+1]/Fibonacci[n-k+1])(b-a)
(* endif *) ];
(* enddo *),{k,1,n-1}];
{a,b}
];
Example of call :
FibonacciMaximum[-3x^2+22x+1, x, 0., 10., 0.01]
Out[1]={3.66312,3.66938}
hth
---
jcp
Prev by Date:
**Re: Arbitrary-precision numbers in patterns**
Next by Date:
**Re: Mathematica + NETLink + CodeDom- Example 2**
Previous by thread:
**Understanding Fibonacci Search**
Next by thread:
**Re: queueing theory : sample code**
| |