title: MATLAB Perceptron from scratch - OR function
body: <p>my first time asking a question.</p>
  
  <p>I'm teaching myself neural networks and am currently trying to program a perceptron algorithm. I want to train it for the OR function, but it isn't working. I have absolutely no idea regarding what I am doing wrong, and there are no solutions on the internet that don't use a toolbox.</p>
  
  <pre><code>input = [0 0; 0 1; 1 0; 1 1]%input vector
  num_in = 4;% number of iterations
  desired_out = [0;1;1;1] %desired output
  bias = -1; %bias
  w=zeros(2,1); %weight vector, initially zero
  iterations = 100; % number of iterations to go through
  
  for i = 1:iterations
       out = zeros(4,1);
       for j = 1:num_in %go per row of x
            y = bias+input(j,1)*w(1,1)+input(j,2)*w(2,1) %sum
            if(out(j,1)~=desired_out(j,1))  % modify weights and bias if mismatch exists
               bias = bias+desired_out(j,1);
               w(1,1) =w(1,1)+input(j,1)*desired_out(j,1);
               w(2,1) = w(2,1)+input(j,2)*desired_out(j,1);
            end
       end
  end
  out %print the output
  </code></pre>