function [wo, wi] = ThreeDBayesBoundary(p, q, Pw1, Pw2)
%[wo, wi] = ThreeDBayesBoundary(p, q, Pw1, Pw2)
%
% This function will determine and plot the 3D Bayes Decision Boundary
% Plane usuing MatLab.  It's inputs p and q are the probabilities of
% P(x=1|w1) while q = P(x=1|w2).  The vectors p and q are of size 3 and
% range between 0 and 1.  Note that if 0 or 1 is chosen, an error will
% occur.  Pw1 and Pw2 are the priors and should sum to 1.
%
% Outputs the weights in wo and wi along with plotting the plane using
% MatLab's MESH feature.
% Note: the vectors are all column vectors.

wo=0;
wi=[0 0 0]';
              
        wo = sum(log((1-p)./(1-q))) + 3*log(Pw1/Pw2);
        wi = (p.*(1-q))./(q.*(1-p));
        
       
       
if (w(1)~=0)  
    x2 = -1:0.01:1;
    x3 = -1:0.01:1;
    [X2, X3] = meshgrid(-1:0.01:1, -1:0.01:1);
    X1 = (X2*wi(2) + X3*wi(3) + wo)/wi(1);
    mesh(x2, x3, X1);
elseif (w(2)~=0)  
    x1 = -1:0.01:1;
    x3 = -1:0.01:1;
    [X1, X3] = meshgrid(-1:0.01:1, -1:0.01:1);
    X2 = (X1*wi(1) + X3*wi(3) + wo)/wi(2);
    mesh(x1, x3, X2);
elseif (w(3)~=0)  
    x1 = -1:0.01:1;
    x2 = -1:0.01:1;
    [X1, X2] = meshgrid(-1:0.01:1, -1:0.01:1);
    X3 = (X1*wi(1) + X2*wi(2) + wo)/wi(3);
    mesh(x1, x2, X3);
else
    ('There is no plane to draw!')
end
