% Perceptron training in Example 13.7 in Sec. 13.5 in DIP version 4

% Class 1: [3 3 1], Class 2: [1 1 1]

a = 1;  % learning rate

x1 = [3 3 1];
x2 = [1 2 1];

w = [0 0 0];    % initial weight vector

for epoch = 1: 20
    w_prev = w; 
    x = x1; 
    y = dot(w, x);

    if (y <= 0)
        w = w + a*x;
    end
    
    x = x2; 
    y = dot(w, x);

    if (y >= 0)
        w = w - a*x;
    end
    
    if (w == w_prev)
        break; 
    end
end

epoch

w

dot(w, x1)
dot(w, x2)
        
   
    

    
