Sie sind auf Seite 1von 2

To find a maximum solution to given a function, f(x), on the interval [a, b] where the function, f(x), is unimodal.

INPUT: endpoints a, b; tolerance, t


OUTPUT:final interval [ai, bi], f(midpoint)
Step 1.
Step 2.

Initialize the tolerance, t >0.


Set r=0.618 and define the test points
x1 = a + (1-r)(b-a)
x2 = a + r(b-a)

Step 3.

Calculate f(x1) and f(x2)


Compare f(x1) and f(x2)

Step 4.

a. If f(x1) < f(x2), then the new interval is [x1, b]:


a becomes the previous x1
b does not change
x1 becomes the previous x2
Find the new x2 using the formula in Step 2.
b. If f(x1) > f(x2), then the new interval is [a, x2]:
a does not change
b becomes the previous x2
x2 becomes the previous x1
Find the new x1 using the formula in Step 2.
Step 5.
Step 6.

If the length of the new interval from Step 4 is less than the tolerance
specified, the stop. Otherwise go back to Step 3.
Estimate x* as the midpoint of the final interval and compute, f(x*), the
estimated maximum of the function.

STOP

Max -x^2-1 over -1 to 0.75, tolerance =.25


r
Number of experimental iterations

0.61803399
4.04330833

x2

f(x1)

x1

-1

0.75

-0.3315594803

0.08155948 -1.10993169 -1.00665195

f(x2)

-0.33155948

0.75

0.0815594803

0.33688104 -1.00665195 -1.11348883

-0.33155948 0.33688104

-0.0762379212

0.08155948 -1.00581222 -1.00665195

-0.33155948 0.08155948

-0.1737620788

-0.07623792 -1.03019326 -1.00581222

-0.17376208 0.08155948

-0.0762379212

-0.01596468 -1.00581222 -1.00025487

-0.07623792 0.08155948

STOP

|B-A|
1.75
1.08155948
0.66844052
0.41311896
0.25532156
0.1577974

Das könnte Ihnen auch gefallen