function [y,y1,y2,inp]=XOR(wini,alfa) % % This function implements the XOR boolean fucntion using the AND and OR perceptrons derived previously % % Input arguments: % % inp - input matrix (m patterns, n inputs) % tar - target vector % wini - initial value of the weight vector (bias is the (n+1)th weight % alfa - learning rate % % Output arguments: % % w - weight vector history % y - output vector % % obtain the AND percepton load AND w=perlearn(inp,t,[0 0 0],0.05); % obtain the x(neg)y and the output w1=w(41,:); w1(3)=w1(3)+w1(1); w1(1)=-w1(1); y1=perrecal(inp,w1); % obtain the xy(neg) w2=w(41,:); w2(3)=w2(3)+w2(2); w2(2)=-w2(2); y2=perrecal(inp,w2); % obtain the OR perceptron load OR w=perlearn(inp,t,[0 0 0],0.05); w3=w(41,:); %obtain the XOR output y=perrecal([y1' y2'], w3);