12.07.2015 Views

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

COPYRIGHT 2008, PRINCETON UNIVERSITY PRESS

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

58 chapter 33.4.1 Gnuplot Input Data Format ⊙The format of the data file that Gnuplot can read is not confined to (x, y) values.You may also read in a data file as a C language scanf format string xy by invokingthe using option in the plot command. (Seeing that it is common for Linux/Unix programs to use this format for reading files, you may want to read moreabout it.)plot ‘datafile’ { using { xy | yx | y } {"scanf string"} }This format explicitly reads selected rows into x or y values while skipping pasttext or unwanted numbers:gnuplot> plot "data" using "%f%f" Default, 1st x, 2nd y.gnuplot> plot "data" using yx "%f %f" Reverse, 1st y, 2nd x.gnuplot> plot "data" xy using "%*f %f %*f %f" Use row 2,4 for x, y.gnuplot> plot "data" using xy "%*6c %f%*7c%f"This last command skips past the first six characters, reads one x, skips the nextseven characters, and then reads one y. It works for reading in x and y from filessuch as✞☎theta : −20.000000 Energy : −3.041676 theta : −19.000000 Energy :−3.036427 theta : −18.000000 Energy : −3.030596 theta : −17.000000Energy : −3.024081 theta : −16.000000 Energy : −3.016755✝Observe that because the data read by Gnuplot are converted to floating-pointnumbers, you use %f to read in the values you want.Besides reading data from files, Gnuplot can also generate data from userdefinedand library functions. In these cases the default independent variable is xfor 2-D plots and (x, y) for 3-D ones. Here we plot the acceleration of a nonharmonicoscillator:gnuplot> k=10 Set value for kgnuplot> a(x) = .5 * k * x ** 2 Analytic expressiongnuplot> plot [–10:10] a(x) Plot analytic functionA useful feature of Gnuplot is its ability to plot analytic functions along withnumerical data. For example, Figure 3.7 compares the theoretical expression forthe period of a simple pendulum to experimental data of the form✞☎✝# length (cm) period ( sec ) # length (cm) period ( sec )10 0.8 60 1.620 0.9 70 1.730 1.2 80 1.840 1.3 90 1.950 1.5 100 2.0−101<strong>COPYRIGHT</strong> <strong>2008</strong>, PRINCET O N UNIVE R S I T Y P R E S SEVALUATION COPY ONLY. NOT FOR USE IN COURSES.ALLpup_06.04 — <strong>2008</strong>/2/15 — Page 58

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!