python - gnuplot: the "sum [<var> = <start>:<end>] <expression>" strategy -
in following script, plot y(x):
and function u(x):
edit
plotting y(x) easy, having problems plot function u(x).
u(x) same function y(x), summing every step.
therefore, in order plot u(x), have tried sum [<var> = <start>:<end>] <expression> strategy. have implemented notation as:
replot sum[x=1:6] y(x) line lt -1 lw 1 lc 2 title "u(x)"
in 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 font of letters of legend y(x) = (2*x)/(x**2) plot y(x) line lt -1 lw 1 lc 1 title "y(x)" replot sum[x=1:6] y(x) 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 not sure if sum[x=1:6] y(x) strategy indeed plotting u(x).
in order check this, can following:
we know that:
so, value in gnuplot u(6)? if run script, get:
zooming:
i see u(6) reaching value of 2.0000, , not 3.5835.
this makes me think replot sum[x=1:6] u(x) not plotting u(x_i) (second formula)
how plot u(x) ?.
edit 2
running replot sum[i=1:6] y(i) in 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 font of letters of legend y(x) = (2*x)/(x**2) plot y(x) line lt -1 lw 1 lc 1 title "y(x)" replot sum[i=1:6] y(i) 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 following: u(6) = 3.000:
edit 3
using y(x) = (2.*x)/(x**2) or y(x) = (2.*x)/(x**2.), u(6) = 4.9:
edit 4
making:
n=100 replot sum[i=0:n-1] y(1. + (i+0.5)*5./n)*5./n line lt -1 lw 1 lc 5 title "sum(x)" produces constant (cyan line) y=3.58. result of numerical approximation of summation.
what want achieve plot function u(x) values of x_{i}... in @ every step i, summation on previous steps performed, , new value of u generated. plot function u(x)...
in fact, plotted u(x) 6*y(x), can check if replace in script line
plot y(x) line lt -1 lw 1 lc 1 title "y(x)" with
plot 6*y(x) line lt -1 lw 1 lc 1 title "y(x)" that line coincide u(x).
also, note function y(x) not integrable in interval [0, 6] since behaves @ 0 1/x (in formula, obtain expression ln(0)).










Comments
Post a Comment