-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIB.m
More file actions
32 lines (32 loc) · 704 Bytes
/
FIB.m
File metadata and controls
32 lines (32 loc) · 704 Bytes
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
31
32
f=inline(input('Enter a function f(x) for minimization case','s'));
a=input('Enter the starting point of search point');
b=input('Enter the ending point of search point');
n=input('Enter the number of function evaluations');
F(1)=1;
F(2)=1;
for i=1:n+1
F(2+i)=F(i+1)+F(i);
end
L=b-a;
k=2;
Lk=F(n-k+2)*L/F(n+2);
x1=a+Lk;
x2=b-Lk;
for k=2:n
if f(x1)>=f(x2)
a=x1;
fprintf('\n New interval at iteration %d is %6.4f and %6.4f',k-1,a,b);
k=k+1;
Lk=F(n-k+2)*L/F(n+2);
x1=a+Lk;
x2=b-Lk;
else
b=x2;
fprintf('\n New interval at iteration %d is %6.4f and %6.4f',k-1,a,b);
k=k+1;
Lk=F(n-k+2)*L/F(n+2);
x1=a+Lk;
x2=b-Lk;
end
end
fprintf('\n Final interval is %6.4f and %6.4f \n',a,b);