function G = QDC_Satimage(M,S,P,X,y)
% QDC_Satimage
%
G=[];
syms x1;
syms x2;
a1=[x1 x2];
b1=[x1;x2];
[N,l]=size(X);
[l,c]=size(M);
for j=1:c
t=-1/2*a1*inv(S(:,:,j))*b1+(inv(S(:,:,j))*M(:,j))'*b1-...
1/2*(M(:,j))'*inv(S(:,:,j))*M(:,j)-1/2*log(det((S(:,:,j))))+...
log(P(j));
G=[G;t];
end
tt=[];
for i=1:c
u=expand(G(i));
tt=[tt;u];
end
t12=tt(1)-tt(2);
t13=tt(1)-tt(3);
t14=tt(1)-tt(4);
t15=tt(1)-tt(5);
t17=tt(1)-tt(6);
t23=tt(2)-tt(3);
t24=tt(2)-tt(4);
t25=tt(2)-tt(5);
t27=tt(2)-tt(6);
t34=tt(3)-tt(4);
t35=tt(3)-tt(5);
t37=tt(3)-tt(6);
t45=tt(4)-tt(5);
t47=tt(4)-tt(6);
t57=tt(5)-tt(6);
G12=solve(t12,x2);
G13=solve(t13,x2);
G14=solve(t14,x2);
G15=solve(t15,x2);
G17=solve(t17,x2);
G23=solve(t23,x2);
G24=solve(t24,x2);
G25=solve(t25,x2);
G27=solve(t27,x2);
G34=solve(t34,x2);
G35=solve(t35,x2);
G37=solve(t37,x2);
G45=solve(t45,x2);
G47=solve(t47,x2);
G57=solve(t57,x2);
temp1=[0 0];
temp2=[0 0];
temp3=[0 0];
temp4=[0 0];
temp5=[0 0];
temp7=[0 0];
for i=1:N
if (y(i)==1)
temp1=[temp1 ;X(i,:)];
elseif (y(i)==2)
temp2=[temp2 ;X(i,:)];
elseif (y(i)==3)
temp3=[temp3 ;X(i,:)];
elseif (y(i)==4)
temp4=[temp4 ;X(i,:)];
elseif (y(i)==5)
temp5=[temp5 ;X(i,:)];
else (y(i)==7)
temp7=[temp7 ;X(i,:)];
end
end
hold on;
scatter(temp1(:,1),temp1(:,2),'b+');
scatter(temp2(:,1),temp2(:,2),'go');
scatter(temp3(:,1),temp3(:,2),'rx');
scatter(temp4(:,1),temp4(:,2),'cv');
scatter(temp5(:,1),temp5(:,2),'ms');
scatter(temp7(:,1),temp7(:,2),'y*');
h121=ezplot(G12(1),[25,160]);
set(h121, 'Color', 'c','LineWidth',3);
h122=ezplot(G12(2),[25,160]);
set(h122, 'Color', 'c','LineWidth',3);
h131=ezplot(G13(1),[25,160]);
set(h131, 'Color', 'm','LineWidth',3);
h132=ezplot(G13(2),[25,160]);
set(h132, 'Color', 'm','LineWidth',3);
h141=ezplot(G14(1),[25,160]);
set(h141, 'Color', 'y','LineWidth',3);
h142=ezplot(G14(2),[25,160]);
set(h142, 'Color', 'y','LineWidth',3);
h152=ezplot(G15(2),[25,160]);
set(h152, 'Color', 'r','LineWidth',3);
h151=ezplot(G15(1),[25,160]);
set(h151, 'Color', 'r','LineWidth',3);
h171=ezplot(G17(1),[25,160]);
set(h171, 'Color', 'g','LineWidth',3);
h172=ezplot(G17(2),[25,160]);
set(h172, 'Color', 'g','LineWidth',3);
h231=ezplot(G23(1),[25,160]);
set(h231, 'Color', 'y','LineWidth',2);
h232=ezplot(G23(2),[25,160]);
set(h232, 'Color', 'y','LineWidth',2);
h241=ezplot(G24(1),[25,160]);
set(h241, 'Color',[0 .3 0],'LineWidth',2);
h242=ezplot(G24(2),[25,160]);
set(h242, 'Color',[0 .3 0],'LineWidth',2);
h251=ezplot(G25(1),[25,160]);
set(h251, 'Color',[.6 0 1],'LineWidth',2);
h252=ezplot(G25(2),[25,160]);
set(h252, 'Color',[.6 0 1],'LineWidth',2);
h271=ezplot(G27(1),[25,160]);
set(h271, 'Color',[.5 .7 .6],'LineWidth',2);
h272=ezplot(G27(2),[25,160]);
set(h272, 'Color',[.5 .7 .6],'LineWidth',2);
h341=ezplot(G34(1),[25,160]);
set(h341, 'Color', [0 0 .2],'LineWidth',2);
h342=ezplot(G34(2),[25,160]);
set(h342, 'Color', [0 0 .2],'LineWidth',2);
h351=ezplot(G35(1),[25,160]);
set(h351, 'Color',[1 .5 0],'LineWidth',2);
h352=ezplot(G35(2),[25,160]);
set(h352, 'Color',[1 .5 0],'LineWidth',2);
h372=ezplot(G37(2),[25,160]);
set(h372, 'Color',[.5 1 0],'LineWidth',2);
h371=ezplot(G37(1),[25,160]);
set(h371, 'Color',[.5 1 0],'LineWidth',2);
h451=ezplot(G45(1),[25,160]);
set(h451, 'Color',[.6 .2 0],'LineWidth',2);
h45=ezplot(G45(2),[25,160]);
set(h45, 'Color',[.6 .2 0],'LineWidth',2);
h471=ezplot(G47(1),[25,160]);
set(h471, 'Color',[.1 0 0],'LineWidth',2);
h472=ezplot(G47(2),[25,160]);
set(h472, 'Color',[.1 0 0],'LineWidth',2);
h571=ezplot(G57(1),[25,160]);
set(h571, 'Color',[0 .5 1],'LineWidth',2);
h572=ezplot(G57(2),[25,160]);
set(h572, 'Color',[0 .5 1],'LineWidth',2);
axis([20 140 20 140])
xlabel('x1');
ylabel('x2');
title('Clases y Fronteras');
legend('clase 1','clase 2','clase 3','clase 4','clase 5','clase 7','Front 12','','Front 13','','Front 14','','Front 15','','Front 17','','Front 23'...
,'','Front 24','','Front 25','','Front 27','','Front 34','','Front 35','','Front 37'...
,'','Front 45','','Front 47','','Front 57');
clc;
end