X=[1,0,0;1,0,1;1,1,0;1,1,1]; W=[0.5,0.5,0.5]; d=[-1,1,1,1]; r=0.9; for n=1:1:1000 m=W(n,1)+W(n,2)*X(mod(n-1,4)+1,2)+W(n,3)*X(mod(n-1,4)+1,3); if(m<0) y=-1; else y=1; end WW=W(n,:)+r*(d(mod(n-1,4)+1)-y)*X(mod(n-1,4)+1,:); WW=WW'; W=W'; W=[W,WW]; W=W'; end plot(0,0,'.'); hold on; plot(0,1,'x'); hold on; plot(1,0,'x'); hold on; plot(1,1,'x'); hold on; syms X1 X2; ezplot(W(n,1)+X1*W(n,2)+X2*W(n,3));