Reputation: 677
In the following script, I would like to plot y(x)
:
and this function u(x)
:
EDIT
Plotting y(x)
is easy, but I am having problems to plot the function u(x)
.
u(x)
is just the same function as y(x)
, but summing every step.
Therefore, in order to plot u(x)
, I have tried the sum [<var> = <start>:<end>] <expression>
strategy. I have implemented this notation as:
replot sum[x=1:6] y(x) with line lt -1 lw 1 lc 2 title "u(x)"
in the following script:
#
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
I am not sure if the sum[x=1:6] y(x)
strategy is indeed plotting u(x)
.
In order to check this, we can do the following:
we know that:
So, what is the value in gnuplot for u(6)
? If you run that script, you get:
zooming:
I see that u(6)
is reaching the value of 2.0000
, and not 3.5835
.
This makes me think that the replot sum[x=1:6] u(x)
is not plotting u(x_i) (second formula)
How could I plot u(x)
?.
EDIT 2
Running replot sum[i=1:6] y(i)
in this script:
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
produces the following: u(6) = 3.000
:
EDIT 3
Using y(x) = (2.*x)/(x**2)
or y(x) = (2.*x)/(x**2.)
, I get u(6) = 4.9
:
EDIT 4
Making:
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)"
produces a constant (cyan line) y=3.58
. This is the result of the numerical approximation of the summation.
What I really want to achieve is to plot the function u(x)
for all the values of x_{i}
... in which at every step i
, the summation over all the previous steps is performed, and a new value of u
is generated. I would like to plot the function u(x)
...
Upvotes: 0
Views: 221
Reputation: 13087
In fact, what is actually plotted as u(x)
is just 6*y(x)
, you can check that if you replace in your script the line
plot y(x) with line lt -1 lw 1 lc 1 title "y(x)"
with
plot 6*y(x) with line lt -1 lw 1 lc 1 title "y(x)"
that the line will then coincide with u(x)
.
Also, note that the function y(x)
is not integrable in the interval [0, 6]
since it behaves at 0
as 1/x
(in your formula, you would obtain expression ln(0)
).
Upvotes: 1