Why do we need weights when training a perceptron as an OR gate? Without using any of Matlab's neural network tools, I'm writing a program to simulate an OR gate with a perceptron. I have seen many tutorials, but I still can't understand why we need weights to train a perceptron for such a simple purpose.  

One way is to program the perceptron with the conditions (0,0)=0. (1,0)=1. (0,1)=1. (1,1)=1. So the two inputs to the perceptron would be either zeroes or ones. I don't see the purpose of weights here. Assuming weights are 1, for the second training example, the output would be 1*1 + 0*1 = 1. For the last example, it would be 1*1 + 1*1 = 2. So an activation function which says if output &gt;= 1, output = 1 else output =0; end should suffice. This would successfully simulate an OR gate. So why do I need to "train" any weights?
This would successfully simulate an OR gate.


Of course. In fact, hardware implementation of an OR gate needs just a few transistors. It may sound surprising, but the best python implementation of OR is a or b.


  So why do I need to "train" any weights?


It's one of the simplest functions out there, everyone understands how OR works just from the boolean table. The task shows that a neural network can learn it as well, just from examples and without specification what a logical operation is and how to wire it.