Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear()
- clf()
- x1arr=[1,-1,-1,1];
- x2arr=[1,1,-1,-1];
- e=[1,1,0,0];
- alpha=rand();
- w1=rand();
- w2=rand();
- T=0;
- L=0;
- x1=2;
- x2=-2;
- finito=0;
- while finito==0
- finito=1;
- for i =1:4
- S=x1arr(i)*w1+x2arr(i)*w2-T;
- if(S>0)
- then
- Y=1
- color_point="green"
- else
- Y=0
- color_point="red"
- end
- scatter(x1arr(i),x2arr(i),60,color_point,"fill");
- if(Y~=e(i))
- then
- w1=w1-alpha*(Y-e(i))*x1arr(i);
- w2=w2-alpha*(Y-e(i))*x2arr(i);
- T=T+alpha*(Y-e(i));
- finito=0;
- end
- end
- end
- L=x*(-w1/w2)+(T/w2);
- plot(x,L, 'LineWidth',2);
- xgrid
- xlabel('x1')
- ylabel('x2')
- a=0;
- b=0;
- while 1
- newX1=input("Podaj x1: ")
- newX2=input("Podaj x2: ")
- S=newX1*w1+newX2*w2-T;
- if(S>0)
- then
- Y=1
- color_point="green"
- disp("Y: 1");
- else
- Y=0
- color_point="red"
- disp("Y: 0");
- end
- scatter(newX1,newX2,60,color_point,"fill");
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement