Using Matlab's conv() function Here is an example of convolution given:



I have two questions here:


Why is the vector  padded with two 0s on each side? As, the length of kernel ℎ is 3. If  is padded with one 0 on each side, the middle element of convolution output would be within the range of the length of , why not one 0 on each side? 
Explain the following output to me:  

 &gt;&gt; x = [1, 2, 1, 3];  
 &gt;&gt; h = [2, 0, 1];  
 &gt;&gt; y = conv(x, h, 'valid')      
  y =    
      3     8  
 &gt;&gt;   


What is valid doing here in the context of the previously shown mathematics on vectors  and ℎ?
For your second question, valid means the range of output where there is full overlap between the convolving signals. 

Note that for two causal signals, $x[n]$ of length $L_x$ and $h[n]$ of length $L_h$ the convolution output $y[n]$ will be of length $L_y = L_x + L_h -1$. 

However among those output $y[n]$ samples, the first $L_d = \min\{L_x,L_h\} -1$ and the last $L_d= \min\{L_x,L_h\} -1$ samples will be computed with partial overlaps between $x[n]$ and $y[n]$ (whicih are the edge samples) but the remaining portion (that's in the center) will be be computed by full overlap with the shorter sequence being fully inside the longer sequence.

In your case; $L_x = 4$ and $L_h=3$ then the first and last $2$ samples will be discarded and the center $2$ samples will be returned.