File: approximate.dem

package info (click to toggle)
gnuplot 5.0.5%2Bdfsg1-6%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,800 kB
  • ctags: 8,062
  • sloc: ansic: 78,152; cpp: 6,981; makefile: 2,075; sh: 1,343; lisp: 655; perl: 302; awk: 235; pascal: 194; tcl: 88; python: 46
file content (38 lines) | stat: -rw-r--r-- 1,221 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#
# Show use of pseudodata mechanism '+' to use plot styles with more than 
# one relevant value per x coordinate. In this example we use the style
# "filledcurves" to show the difference between two analytic functions.
# This corresponds to the specification of multiple columns in the 
# 'using' option for input from data files.
# 
#
approx_1(x) = x - x**3/6
approx_2(x) = x - x**3/6 + x**5/120 
approx_3(x) = x - x**3/6 + x**5/120 - x**7/5040

label1 = "x - {x^3}/3!"
label2 = "x - {x^3}/3! + {x^5}/5!"
label3 = "x - {x^3}/3! + {x^5}/5! - {x^7}/7!"

#
set termoption enhanced
save_encoding = GPVAL_ENCODING
set encoding utf8
#
set title "Polynomial approximation of sin(x)"
set key Left center top reverse
set xrange [ -3.2 : 3.2 ]
set xtics ("-π" -pi, "-π/2" -pi/2, 0, "π/2" pi/2, "π" pi)
set format y "%.1f"
set samples 500
set style fill solid 0.4 noborder

plot '+' using 1:(sin($1)):(approx_1($1)) with filledcurve title label1 lt 3, \
     '+' using 1:(sin($1)):(approx_2($1)) with filledcurve title label2 lt 2, \
     '+' using 1:(sin($1)):(approx_3($1)) with filledcurve title label3 lt 1, \
     sin(x) with lines lw 1 lc rgb "black"

pause -1 "Hit return to continue"

set encoding save_encoding
reset