clc
clear all
% In mathematics, two quantities are in the golden ratio if their ratio is the same
% as the ratio of their sum to the larger of the two quantities.
% The golden ratio also is called the golden mean or golden section
% Other names include extreme and mean ratio, medial section, divine proportion,
% divine section (Latin: sectio divina), golden proportion, golden cut, and golden number.
% RESITEV (7.85,-61.6225)
a=-50
b=100
k1=0.382;
k2=0.618;
c=k1*(b-a)
d=0.618*(b-a)
x=a
ya=-x.*(5*3.14-x);
x=b
yb=-x.*(5*3.14-x);
x=c
yc=-x.*(5*3.14-x);
x=d
yd=-x.*(5*3.14-x);
for i=1:5
if yd>yc;
a=a
b=d
c=a+(b-a)*0.382
d=a+(b-a)*0.618
x=a
ya=-x.*(5*3.14-x);
x=b
yb=-x.*(5*3.14-x);
x=c
yc=-x.*(5*3.14-x);
x=d
yd=-x.*(5*3.14-x);
y=[yc, yd]
Y1=min(y)
fprintf('\na1=%.4f',a)
fprintf('\nY1=%.4f',Y1)
fprintf('\nb1=%.4f',b)
elseif yc>yd
a=c
b=b
c=a+(b-a)*0.382
d=a+(b-a)*0.618
x=a
ya=-x.*(5*3.14-x);
x=b
yb=-x.*(5*3.14-x);
x=c
yc=-x.*(5*3.14-x);
x=d
yd=-x.*(5*3.14-x);
y=[yc, yd]
Y2=min(y)
fprintf('\na2=%.4f',a)
fprintf('\nY2=%.4f',Y2)
fprintf('\nb2=%.4f',b)
else
disp('Nekaj je narobe')
end
end