gnuplot: the "sum [<var> = <start>:<end>] <expression>" strategy
<p>In the following script, I would like to plot <code>y(x)</code>:</p>

<p><a href="http://i.stack.imgur.com/LrUF9.png" rel="nofollow"><img src="http://i.stack.imgur.com/LrUF9.png" alt="enter image description here"></a></p>

<p>and this function <code>u(x)</code>:</p>

<p><a href="http://i.stack.imgur.com/KiqoI.png" rel="nofollow"><img src="http://i.stack.imgur.com/KiqoI.png" alt="enter image description here"></a></p>

<p><strong>EDIT</strong></p>

<p>Plotting <code>y(x)</code> is easy, but I am having problems to plot the function <code>u(x)</code>. </p>

<p><code>u(x)</code> is just the same function as <code>y(x)</code>, but summing every step.</p>

<p>Therefore, in order to plot <code>u(x)</code>, I have tried the <code>sum [&lt;var&gt; = &lt;start&gt;:&lt;end&gt;] &lt;expression&gt;</code> strategy. I have implemented this notation as: </p>

<p><code>replot sum[x=1:6] y(x) with line lt -1 lw 1 lc 2 title "u(x)"</code></p>

<p>in the following script:</p>

<pre><code> #

 set ylabel "y" font  ", 20"
 set xlabel 'x' font  ", 20"


 set format y "%9.4f"
 set xrange [1:6]

 set yrange [0:20]
 set xtics font ", 15"
 set ytics font ", 15"


 set key font ",17" # Changes the font of the letters of the legend

 y(x) = (2*x)/(x**2)
 plot y(x) with line lt -1 lw 1 lc 1 title "y(x)"
 replot sum[x=1:6] y(x) with line lt -1 lw 1 lc 2 title "u(x)"


 pause -1
 set term post enh color eps
 set output "y_x.eps"
 replot
</code></pre>

<p>I am not sure if the <code>sum[x=1:6] y(x)</code> strategy is indeed plotting <code>u(x)</code>.</p>

<p>In order to check this, we can do the following: </p>

<p>we know that:</p>

<p><a href="http://i.stack.imgur.com/mq3O0.png" rel="nofollow"><img src="http://i.stack.imgur.com/mq3O0.png" alt="enter image description here"></a></p>

<p>So, what is the value in gnuplot for <code>u(6)</code>? If you run that script, you get:</p>

<p><a href="http://i.stack.imgur.com/XoFFx.png" rel="nofollow"><img src="http://i.stack.imgur.com/XoFFx.png" alt="enter image description here"></a></p>

<p>zooming:</p>

<p>I see that <code>u(6)</code> is reaching the value of <code>2.0000</code>, and not <code>3.5835</code>.</p>

<p>This makes me think that the <code>replot sum[x=1:6] u(x)</code> is not plotting u(x_i) (second formula)</p>

<p>How could I plot <code>u(x)</code> ?.</p>

<p><a href="http://i.stack.imgur.com/vIg6P.png" rel="nofollow"><img src="http://i.stack.imgur.com/vIg6P.png" alt="enter image description here"></a></p>

<p><strong>EDIT 2</strong></p>

<p>Running <code>replot sum[i=1:6] y(i)</code> in this script:</p>

<pre><code>set ylabel "y" font  ", 20"
set xlabel 'x' font  ", 20"


 set format y "%9.4f"

 set xrange [1:6]

 set yrange [0:20]
 set xtics font ", 15"
 set ytics font ", 15"


 set key font ",17" # Changes the font of the letters of the legend

 y(x) = (2*x)/(x**2)
 plot y(x) with line lt -1 lw 1 lc 1 title "y(x)"


 replot sum[i=1:6] y(i) with line lt -1 lw 1 lc 2 title "u(x)"

 pause -1
 set term post enh color eps
 set output "y_x.eps"
 replot
</code></pre>

<p>produces the following: <code>u(6) = 3.000</code>:</p>

<p><a href="http://i.stack.imgur.com/j9WMA.png" rel="nofollow"><img src="http://i.stack.imgur.com/j9WMA.png" alt="enter image description here"></a></p>

<p><a href="http://i.stack.imgur.com/w3r72.png" rel="nofollow"><img src="http://i.stack.imgur.com/w3r72.png" alt="enter image description here"></a></p>

<p><strong>EDIT 3</strong></p>

<p>Using <code>y(x) = (2.*x)/(x**2)</code> or <code>y(x) = (2.*x)/(x**2.)</code>, I get <code>u(6) = 4.9</code>:</p>

<p><a href="http://i.stack.imgur.com/0rTqQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/0rTqQ.png" alt="enter image description here"></a></p>

<p><a href="http://i.stack.imgur.com/YSe3P.png" rel="nofollow"><img src="http://i.stack.imgur.com/YSe3P.png" alt="enter image description here"></a></p>

<p><strong>EDIT 4</strong></p>

<p>Making:</p>

<pre><code>N=100
replot sum[i=0:N-1] y(1. + (i+0.5)*5./N)*5./N with line lt -1 lw 1 lc 5 title "sum(x)"
</code></pre>

<p>produces a constant (cyan line) <code>y=3.58</code>. This is the result of the numerical approximation of the summation.</p>

<p><a href="http://i.stack.imgur.com/uoqAP.png" rel="nofollow"><img src="http://i.stack.imgur.com/uoqAP.png" alt="enter image description here"></a></p>

<p>What I really want to achieve is to plot the function <code>u(x)</code> for all the values of <code>x_{i}</code>... in which at every step <code>i</code>, the summation over all the previous steps is performed, and a new value of <code>u</code> is generated. I would like to plot the function <code>u(x)</code>...</p>

<p>In fact, what is actually plotted as <code>u(x)</code> is just <code>6*y(x)</code>, you can check that if you replace in your script the line</p>

<pre><code>plot y(x) with line lt -1 lw 1 lc 1 title "y(x)"
</code></pre>

<p>with</p>

<pre><code>plot 6*y(x) with line lt -1 lw 1 lc 1 title "y(x)"
</code></pre>

<p>that the line will then coincide with <code>u(x)</code>.</p>

<p>Also, note that the function <code>y(x)</code> is not integrable in the interval <code>[0, 6]</code> since it behaves at <code>0</code> as <code>1/x</code> (in your formula, you would obtain expression <code>ln(0)</code>).</p>

python sum gnuplot