title: Calculating sum of gradients with awk
body: <p>I have a file that contains 4 columns such as:</p>
  
  <pre><code>A  B  C  D
  1  2  3  4
  10 20 30 40
  100 200 300 400
  .
  .
  .
  </code></pre>
  
  <p>I can calculate gradient of columns B to D versus A such as following commands:</p>
  
  <pre><code>NR&gt;1{print $0,($2-b)/($1-a)}{a=$1;b=$2}' file
  </code></pre>
  
  <p>How can I print sum of gradients as the 5th column in the file? The results should be:</p>
  
  <pre><code>A  B  C  D sum
  1  2  3  4 1+2+3+4=10
  10 20 30 40 (20-2)/(10-1)+(30-3)/(10-1)+(40-4)/(10-1)=9
  100 200 300 400 (200-20)/(100-10)+(300-30)/(100-10)+(400-40)/(100-10)=9
  .
  .
  .
  </code></pre>