summaryrefslogtreecommitdiff
path: root/413/CH7/EX7.2/Example_7_2.sce
blob: 2fd122a96e2c73fef32001ca33e17f03d950ce7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
clc
clear
a=-3
b=1
r=0.618034
function a=f(x)
    a=exp(x)+2-cos(x);
endfunction
xl=a+(1-r)*(b-a)
xr=a+r*(b-a)
FL=f(xl)
FR=f(xr)
while (abs(xr-xl)>0.001)
    T=[xl,xr,FL,FR,a,b,a-b]
    disp(T)
    if(FR >FL)
        b=xr
        xr=xl
        FR=FL
        xl=a+(1-r)*(b-a)
        FL=f(xl)
            else 
        a=xl
        xl=xr
        FL=FR
        xr=a+r*(b-a)
        FR=f(xr)
        end 
   
end