Advertisement
lukifrancuz

Modelowanie_Lab1

Jan 10th, 2023
1,909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 1.10 KB | None | 0 0
  1. clear()
  2. clf()
  3.  
  4. x1arr=[1,-1,-1,1];
  5. x2arr=[1,1,-1,-1];
  6. e=[1,1,0,0];
  7. alpha=rand();
  8. w1=rand();
  9. w2=rand();
  10. T=0;
  11. L=0;
  12. x1=2;
  13. x2=-2;
  14. finito=0;
  15.  
  16. while finito==0
  17.     finito=1;
  18.     for i =1:4
  19.         S=x1arr(i)*w1+x2arr(i)*w2-T;
  20.      
  21.         if(S>0)
  22.         then
  23.             Y=1
  24.             color_point="green"
  25.         else
  26.             Y=0
  27.             color_point="red"
  28.         end
  29.        
  30.         scatter(x1arr(i),x2arr(i),60,color_point,"fill");
  31.        
  32.         if(Y~=e(i))
  33.         then
  34.             w1=w1-alpha*(Y-e(i))*x1arr(i);
  35.             w2=w2-alpha*(Y-e(i))*x2arr(i);
  36.             T=T+alpha*(Y-e(i));
  37.             finito=0;
  38.         end
  39.     end
  40. end
  41. L=x*(-w1/w2)+(T/w2);
  42. plot(x,L, 'LineWidth',2);
  43. xgrid
  44. xlabel('x1')
  45. ylabel('x2')
  46.  
  47. a=0;
  48. b=0;
  49.  
  50. while 1
  51.     newX1=input("Podaj x1: ")
  52.     newX2=input("Podaj x2: ")
  53.     S=newX1*w1+newX2*w2-T;
  54.    
  55.     if(S>0)
  56.     then
  57.         Y=1
  58.         color_point="green"
  59.         disp("Y: 1");
  60.     else
  61.         Y=0
  62.         color_point="red"
  63.         disp("Y: 0");
  64.     end
  65.        
  66.     scatter(newX1,newX2,60,color_point,"fill");
  67. end
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement