File: approximate.dem

package info (click to toggle)
gnuplot 4.6.0-8
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 16,920 kB
  • sloc: ansic: 84,661; cpp: 6,631; lisp: 5,013; makefile: 2,129; sh: 1,092; objc: 647; asm: 539; perl: 298; awk: 235; pascal: 194; csh: 179; tcl: 88; python: 46
file content (36 lines) | stat: -rw-r--r-- 1,163 bytes parent folder | download | duplicates (4)
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
#
# 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
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"

reset