Blame demo/approximate.dem

Packit 0986c0
#
Packit 0986c0
# Show use of pseudodata mechanism '+' to use plot styles with more than 
Packit 0986c0
# one relevant value per x coordinate. In this example we use the style
Packit 0986c0
# "filledcurves" to show the difference between two analytic functions.
Packit 0986c0
# This corresponds to the specification of multiple columns in the 
Packit 0986c0
# 'using' option for input from data files.
Packit 0986c0
# 
Packit 0986c0
#
Packit 0986c0
approx_1(x) = x - x**3/6
Packit 0986c0
approx_2(x) = x - x**3/6 + x**5/120 
Packit 0986c0
approx_3(x) = x - x**3/6 + x**5/120 - x**7/5040
Packit 0986c0
Packit 0986c0
label1 = "x - {x^3}/3!"
Packit 0986c0
label2 = "x - {x^3}/3! + {x^5}/5!"
Packit 0986c0
label3 = "x - {x^3}/3! + {x^5}/5! - {x^7}/7!"
Packit 0986c0
Packit 0986c0
#
Packit 0986c0
set termoption enhanced
Packit 0986c0
save_encoding = GPVAL_ENCODING
Packit 0986c0
set encoding utf8
Packit 0986c0
#
Packit 0986c0
set title "Polynomial approximation of sin(x)"
Packit 0986c0
set key Left center top reverse
Packit 0986c0
set xrange [ -3.2 : 3.2 ]
Packit 0986c0
set xtics ("-π" -pi, "-π/2" -pi/2, 0, "π/2" pi/2, "π" pi)
Packit 0986c0
set format y "%.1f"
Packit 0986c0
set samples 500
Packit 0986c0
set style fill solid 0.4 noborder
Packit 0986c0
Packit 0986c0
plot '+' using 1:(sin($1)):(approx_1($1)) with filledcurve title label1 lt 3, \
Packit 0986c0
     '+' using 1:(sin($1)):(approx_2($1)) with filledcurve title label2 lt 2, \
Packit 0986c0
     '+' using 1:(sin($1)):(approx_3($1)) with filledcurve title label3 lt 1, \
Packit 0986c0
     sin(x) with lines lw 1 lc rgb "black"
Packit 0986c0
Packit 0986c0
pause -1 "Hit return to continue"
Packit 0986c0
Packit 0986c0
set encoding save_encoding
Packit 0986c0
reset