SİMPLEX METODU

delete(findall(0,’Type’,’figure’));
%delete(allPlots);
set(0,’DefaultFigureWindowStyle’,’docked’)

%SIMPLEX YONTEMIv v
syms x;
syms y;
syms i; %loop
syms j; %loop
syms n;
C = {‘y’,’m’,’m’,’m’,’m’,’m’,’m’};
OP = sqrt(x.^2 + y.^2);
BP = sqrt(x.^2 + (y-1).^2);
CP = sqrt((x-2).^2 + (y-1).^2);
V = (OP – 0.5).^2 + 2*(BP – 0.5).^2 + 3*(CP – 0.5).^2;

Error = 0.00001;
counter = 0;
delay = 0.30;
BublesTemp = [0,0];
temp = [0,0];
temp = [temp ; [0,0]];
temp1 = [0,0];
temp2 = [0,0];
index = 1;
anchor = 0;

% y = input(‘f(x) Fonksiyonunu giriniz = ‘);
% a = input(‘(a) Başlangıç değerini giriniz = ‘);
% Error = input(‘(E) Hata Değerini Giriniz = ‘);
N = 14;
xVal = zeros(1,N);
yVal = zeros(1,N);
sVal = zeros(1,N);
% c1 = 1;
% c2 = 2;
az = 60;
el = 15;
azStep = -16*pi/(N);
elStep = 48*pi/(N);
zoomFactor = 1.05;

%figure(‘Name’,char(V));
figure(‘Name’,’SIMPLEX’);
set(gcf,’NumberTitle’,’off’);
clf;
BORDER = 1.5;
[X,Y] = meshgrid(-0.618*BORDER:.05:BORDER/0.618);
R = subs(V,{x,y},{X Y});

view(az,el);
xlabel (‘X’);
ylabel (‘Y’);
plot3(X,Y,R,’:’,’MarkerSize’,10);

%cla;
%patch(X,Y,R,R,’EdgeColor’,’interp’,’FaceColor’,’none’)
title([‘\fontsize{9} \color{red}’,char(V)]);
%mesh(X,Y,R,R,’FaceLighting’,’gouraud’,’LineWidth’,0.01)
hold on;
%axis([-0.618*BORDER BORDER/0.618 -0.618*BORDER BORDER/0.618]);
axis tight;
hidden off;
SimplexStep = 0.5;
%% CALCULATION OF FIRST 4 VALUE
xVal(1) = 0;
yVal(1) = 0;
xVal(2) = xVal(1) + 0;
yVal(2) = yVal(1) + SimplexStep;
xVal(3) = (xVal(1)+xVal(2))/2 + (SimplexStep * cos(pi/6));
yVal(3) = yVal(1) + (SimplexStep * sin(pi/6)); % + (yVal(1)+yVal(2))/2

xAvg = 0.5 * (xVal(3)+xVal(2));
yAvg = 0.5 * (yVal(3)+yVal(2));
xVal(4) = xVal(1) + 2 * (xAvg – xVal(1));
yVal(4) = yVal(1) + 2 * (yAvg – yVal(1));

sVal(1) = subs(V,{x,y},{xVal(1) yVal(1)});
for i = 2:4
sVal(i) = subs(V,{x,y},{xVal(i) yVal(i)});
% text(xVal(i), yVal(i), [num2str(i),'(‘, num2str(xVal(i)),’,’,num2str(yVal(i)),’)’],’color’,’r’);
text(xVal(i-1), yVal(i-1), sVal(i-1), [num2str(i-1)],’color’,’r’);
pause(delay);
line([xVal(i-1) xVal(i)], [yVal(i-1) yVal(i)], [sVal(i-1) sVal(i)],’color’,’k’, ‘LineStyle’, ‘–‘);

hold on;
pause(delay);
az = az + azStep;
el= el+elStep/2;
%zoom(zoomFactor);
view(az,el);
end
% sVal(4) = subs(V,{x,y},{xVal(4) yVal(4)});
% % text(xVal(4), yVal(i+1), [num2str(i+1),'(‘, num2str(xVal(i+1)),’,’,num2str(yVal(i+1)),’)’],’color’,’r’);
% text(xVal(i), yVal(i), sVal(i), [num2str(i),'(‘, num2str(sVal(i)),’)’],’color’,’r’);
% pause(delay);

%i = i + 1;
while i < N

%Buble Sort Vertices
chain = 0;
for j=1:2
for k=1:3-j
if (sVal(i-3+k) > sVal(i-4+k))
BublexTemp = xVal(i-3+k);
xVal(i-3+k) = xVal(i-4+k);
xVal(i-4+k) = BublexTemp;

BubleyTemp = yVal(i-3+k);
yVal(i-3+k) = yVal(i-4+k);
yVal(i-4+k) = BubleyTemp;

BublesTemp = sVal(i-3+k);
sVal(i-3+k) = sVal(i-4+k);
sVal(i-4+k) = BublesTemp;
chain = j-k;
else
chain = 0;
end
end
end

%Next Value Calculation
j = length(temp);
if (anchor > 3) && (isequal([temp(j-1,1),temp(j-1,2)],[xVal(i-1),yVal(i-1)]))
anchor = 0 ;
text(xVal(i), yVal(i), sVal(i), [num2str(i)],’color’,’r’);
pause(delay);
xVal(i+1) = 0.5 * (xVal(i)+xVal(i-1));
yVal(i+1) = 0.5 * (yVal(i)+yVal(i-1));
sVal(i+1) = subs(V,{x,y},{xVal(i+1) yVal(i+1)});
text(xVal(i+1), yVal(i+1), sVal(i+1), [num2str(i+1)],’color’,’r’);
pause(delay);
line([xVal(i) xVal(i+1)], [yVal(i) yVal(i+1)], [sVal(i) sVal(i+1)],’color’,’k’, ‘LineStyle’, ‘–‘);
pause(delay);

az = az + azStep;
el= el+elStep/2;
%zoom(zoomFactor);
view(az,el);

if ( sVal(i) > sVal(i-1) )
xVal(i+2) = 0.5 * (xVal(i-2-chain)+xVal(i-1));
yVal(i+2) = 0.5 * (yVal(i-2-chain)+yVal(i-1));
sVal(i+2) = subs(V,{x,y},{xVal(i+2) yVal(i+2)});
else
xVal(i+2) = 0.5 * (xVal(i-2-chain)+xVal(i));
yVal(i+2) = 0.5 * (yVal(i-2-chain)+yVal(i));
sVal(i+2) = subs(V,{x,y},{xVal(i-2-chain) yVal(i-2-chain)});
end
text(xVal(i+2), yVal(i+2), sVal(i+2), [num2str(i+2)],’color’,’r’);
pause(delay);
line([xVal(i+1) xVal(i+2)], [yVal(i+1) yVal(i+2)], [sVal(i+1) sVal(i+2)],’color’,’k’, ‘LineStyle’, ‘–‘);
i = i+2;
%Buble Sort Vertices
chain = 0;
for j=1:2
for k=1:3-j
if (sVal(i-3+k) > sVal(i-4+k))
BublexTemp = xVal(i-3+k);
xVal(i-3+k) = xVal(i-4+k);
xVal(i-4+k) = BublexTemp;

BubleyTemp = yVal(i-3+k);
yVal(i-3+k) = yVal(i-4+k);
yVal(i-4+k) = BubleyTemp;

BublesTemp = sVal(i-3+k);
sVal(i-3+k) = sVal(i-4+k);
sVal(i-4+k) = BublesTemp;
end
end
end
az = az + azStep;
el= el+elStep/2;
%zoom(zoomFactor);
view(az,el);
end

xAvg = 0.5 * (xVal(i)+xVal(i-1));
yAvg = 0.5 * (yVal(i)+yVal(i-1));
xVal(i+1) = xVal(i-2-chain) + 2 * (xAvg – xVal(i-2-chain));
yVal(i+1) = yVal(i-2-chain) + 2 * (yAvg – yVal(i-2-chain));
temp1 = [xVal(i-1) yVal(i-1)];
temp2 = [xVal(i) yVal(i)];

sVal(i+1) = subs(V,{x,y},{xVal(i+1) yVal(i+1)});
% text(xVal(i+1), yVal(i+1), [num2str(i+1),'(‘, num2str(xVal(i+1)),’,’,num2str(yVal(i+1)),’)’],’color’,’r’);
text(xVal(i), yVal(i), sVal(i), [num2str(i)],’color’,’r’);
pause(delay);
line([xVal(i) xVal(i+1)], [yVal(i) yVal(i+1)], [sVal(i) sVal(i+1)],’color’,’k’, ‘LineStyle’, ‘–‘);
pause(delay);
% text(xVal(i+1), yVal(i), [num2str(i+1),'(‘, num2str(sVal(i)),’)’],’color’,’r’);
az = az + azStep;
el= el+elStep/2;
%zoom(zoomFactor);
view(az,el);

%Detection of Corner Repetition
j = length(temp);
if isequal(temp1,[temp(j,1),temp(j,2)])
anchor = anchor + 1;
elseif isequal(temp1,[temp(j-1,1),temp(j-1,2)])
anchor = anchor + 1;
elseif isequal(temp2,[temp(j,1),temp(j,2)])
anchor = anchor + 1;
elseif isequal(temp2,[temp(j-1,1),temp(j-1,2)])
anchor = anchor + 1;
end

temp = [temp ; temp1];
temp = [temp ; temp2];
pause(delay);
i = i + 1;
end
text(xVal(i), yVal(i), sVal(i), num2str(i),’color’,’r’);

%zoom on;
rotate3d on;
% figure(‘Name’,’SIMPLEX’);
% hold on;
% ezsurf(V,[-0.618*BORDER BORDER/0.618]);
% colorbar;
% Drawing=findobj(‘EdgeColor’,’black’);
% set(Drawing,’LineStyle’,’none’)
% Marker = findobj(‘MarkerSize’,10);
% set(Marker,’LineStyle’,’none’);
%
% plot3(xVal,yVal,sVal, ‘color’,’r’);
view(az,el);

%%