Ngày tải lên :
23/01/2014, 06:20
... d
o‐co=ro(bo‐ao)‐ (1 ‐ro)(bo‐ao)
d
o‐co=(2ro‐ 1) (bo‐ao)(2)
vàr
1 đượcchọnsaocho:
b
1 ‐d1= (1 ‐r1)(b1‐a1)(3)
Thay(2)và(3)vào (1) tacó:
(2r
o‐ 1) (bo‐ao)= (1 ‐r1)(b1‐a1)(4)
Nhưvậyđoạn[a,b]bịcongắnbằnghệsốr
ovà(b1‐a1)=ro(bo‐ao)và:
(2r
o‐ 1) (bo‐ao)= (1 ‐r1)ro(bo‐ao)(5)
Rútgọntacó:
... (2r
o‐ 1) = (1 ‐r1)ro (6)
Từ(6)tatínhđượcr
1:
−
=
o
1
o
1r
r
r
(7)
Trong(7),thay
−
=
n1
o
n
f
r
f
tacó:
−
−−
−
−−
−
−
== =
n1
nn1 n2
n
1
n1
n1 n1
n
f
1
ff f
f
r
f
ff
f
TarútrarằngthuậttoántìmFibonaccicóthểbắtđầubằng:
−
=
n1
o
n
f
r
f
−
−
=
n2
1
n1
f
r
f
và:
−−
−
=
n1k
k
nk
f
r
f
,k= 1, 2, ...
386
globalxfuncv
ifnargin<2;
tol= 1. 0e‐6;
end
ifnargin< 1
h=0 .1;
end
ifsize(x,2)> 1
x=xʹ;
end
n=length(x);
df=zeros(n, 1) ;
u=eye(n);
xold=x;
fold=feval(func,xold);
for
i= 1: n
v=u (1: n,i);
[a,b]=goldbracket(@fline,0.0,h);
[s,fmin]=golden(@fline,a,b);
df(i)=fold‐fmin;
fold=fmin;
x=x+s*v;
end
v=x‐xold;
[a,b]=goldbracket(@fline,0.0,h);
[s,fMin]=golden(@fline,a,
b);
x=x+s*v;
ifsqrt(dot(x‐xold,x‐xold)/n)<tol
xmin=x;
ncyc=j;
return
end
imax= 1;
dfmax=df (1) ;
fori=2:n
ifdf(i)>dfmax
376
f0=f 012 (1) ;
f1=f 012 (2);
f2=f 012 (3);
nd=[f0‐f2f1‐f0f2‐f1]*[x1*x1x2*x2x0*x0;x1x2x0]ʹ;
x3=nd (1) /2/nd(2);
f3=feval(f,x3);%Pt. (1)
ifk<=0|abs(x3‐x1)<tolx|abs(f3‐f1)<tolfun
xo=x3;
fo=
f3;
ifk==0
fprintf(ʹDaycothexemladiemcuctieuʹ)
end
else
ifx3<x1
iff3<f1
x 012 =[x0x3x1];
f 012 =[f0f3f1];
else
x 012 =[x3x1x2];
f 012 =[f3f1
f2];
end
else
iff3<=f1
x 012 =[x1x3x2];
f 012 =[f1f3f2];
else
x 012 =[x0x1x3];
f 012 =[f0f1f3];
end
end
[xo,fo]=optquad0(f,x 012 ,f 012 ,tolx,tolfun,k‐ 1) ;
end
Đểtìmđiểmcựctiểutadùngchươngtrình
ctoptquad.m:
clearall,clc
...