Uploaded by sharanya majumder

FACTS

advertisement
FACTS
1. To plot a single function f(x)
gnuplot> plot f(x)
gnuplot> f(x)=sin(x)+cos(x)*exp(-x)
2. To plot two functions f(x) and g(x) together,
gnuplot> plot f(x),g(x)
3. According to the values of the function. However, these ranges can be
altered and set according to your
choice by issuing
gnuplot> set xrange [-3:3]
gnuplot> set yrange [0:10]
before the plot command.
4. To set the x-y axes, say
gnuplot> set zeroaxis
5. To change the number of samples, go for, say
gnuplot> set samples 1000
6. The width of a line can be changed using specifying a relative value after
the individual plot command
(a trace). Thus
gnuplot> plot sin(x) lw 2, cos(x) lw 1
7. The title of an individual trace can be changed from the automatic legend
by specifying the title as a
string value as in
gnuplot> plot sin(x) lw 2 title ’The Sinusoid’
8. If we want to mark some points on a curve, these points can be defined as
a block variable and plotted
with the curve. Suppose we want to mark the two consecutive maxima of a
sin function on the function
itself. The following code achieves this.
gnuplot> $data << EOD
1.57 1.00
7.85 1.00
EOD
gnuplot> set xrange [0:10]
gnuplot> plot sin(x) lw 2, ’$data’ ps 4
9. Multiple plot windows can remain open together, but only the last one is
active; windows cannot
be switched. One of these windows can be the “test” window which
showcases the properties of the
current terminal.
gnuplot> set term win enh 0
gnuplot> test
gnuplot> set term wxt enh 1
plot sin(x)
10. It is frequently useful to show the axis for which x = 0 and y = 0: For these
cases say set zeroaxis
before plotting anything.
11. If you write down the commands one after another in a text file, the file
can be ‘loaded’ each time you
decide to change something about the plot. This is the preferred way to run
gnuplot, as it encourages
both graphical experiments and generation of publication quality graphs with
a high degree of finish.
Assuming such a file (myplot_plt.txt) is present in the current working
directory, it can loaded
(repeatedly) using,
gnuplot> load ’myplot_plt.txt’
Long lines in the file can be split by putting a backslash at a point where it
needs to be continued
to the next line. A good place to break such lines is just after the comma
character which serves to
separate the individual traces, e.g
plot sin(x) lw 3,\
cos(x)
12. Note that you can say reset at the gnuplot prompt to make it forget
almost anything about the
changes in settings (like xrange or zeroaxis) you have made. If all else fails,
exit and restart gnuplot
EXCERCISES
(a) x+ sin x in (-2π,+2π) Instructions: Argue and show with a sketch how this
curve is resulting out of a translation
of the curve sin x by x. Overlay your plot of the final curve on y = x to show
this feature.
Fig: Sin(x)+x
Fig: sin(x)+x overlayed by y=x
(b) x^2+x+1, x ∈ (−3, 3) Instructions: show the zero y axis. Display the point of
intersection of the graph with the y
axis and the point of minima on the curve (Write down the expression as a
complete square + something first in the
analysis part). Choose lw 2 for the function and pt 7 and pt 5 for the function
and the two datapoints. Choose
large points. Change the titles of the curve to “Function” and the data-points
to “Y-intercept” and “Minima”
respectively.
gnuplot> f(x)=(x+0.5)**2-0.75
gnuplot> set yzeroaxis
gnuplot> set xrange(-3:3)
gnuplot> set xrange[-3:3]
gnuplot> plot f(x)
Fig: 1st part of the analysis
gnuplot> f(x)=(x+0.5)**2-0.75
gnuplot> set xrange[-3:3]
gnuplot> set yzeroaxis
gnuplot> plot f(x)
gnuplot> $data<<EOD
0.0033295 -0.496806
-0.496103 -0.74275
EOD
plot f(x) lw 2,'$data' ps 5
(c) x (x^2 − 1) Instructions: mark the origin and the other roots of this
function
gnuplot> f(x)=x*(x**2-1)
gnuplot> set zeroaxis
gnuplot> $data<<EOD
-1 0
10
00
EOD
gnuplot> plot f(x), '$data' ps 5
(d) x^2/x − 1 , y ∈ (−10, 10) Instructions: set the zero axis. Set the number of
samples to about 400. This would take care of the discontinuity of the graph.
Show the two asymptotic lines to this curve. To show the vertical asymptote
make use of the set arrow command (look up help).
set zeroaxis
gnuplot> set yrange[-10:10]
gnuplot> f(x)=x**2/(x-1)
gnuplot> set arrow from 1.00158, graph 0 to 1.00158,graph 1 nohead
gnuplot> plot f(x)
(e) (ax)^2 e^−ax, x ∈ (0, 10) where a = 1, 2, 3 All three traces should appear
on the same plot and colored red, green and blue. Find the approximate
maxima of the three curves by identifying the points using the mouse and
double clicking on them to copy the coordinates to the clipboard. Paste these
coordinates before the plot commands and design arrow commands to
display vertical lines connecting the highest point on the curves to their
respective bases.
gnuplot> f(x)=(x**2)*exp(-x)
gnuplot> g(x)=(4*x**2)*exp(-2*x)
gnuplot> h(x)=(9*x**2)*exp(-3*x)
gnuplot> plot f(x) lc 7, g(x) lc 18, h(x) lc 11
gnuplot> f(x)=(x**2)*exp(-x)
gnuplot> g(x)=(4*x**2)*exp(-2*x)
gnuplot> h(x)=(9*x**2)*exp(-3*x)
gnuplot> set xrange[0:10]
gnuplot> plot f(x) lc 7, g(x) lc 18, h(x) lc 11
gnuplot> set arrow from 0.684106,0 to 0.684106,0.537678
gnuplot> plot f(x) lc 7, g(x) lc 18, h(x) lc 11
gnuplot> set arrow from 1.01352,0 to 1.01352,0.539779
gnuplot> plot f(x) lc 7, g(x) lc 18, h(x) lc 11
gnuplot> set arrow from 1.9866,0 to 1.98626,0.540848
gnuplot> plot f(x) lc 7, g(x) lc 18, h(x) lc 11
FACTS
1. To zoom manually over a part of a graph, change its axis limits.
2. Place the mouse cursor on a part of the curve you are about to zoom.
Then keep CTRL pressed and roll the mouse wheel. This works for both
the win and wxt terminals. Press ‘u’ to get back to the original, un-zoomed
level.
3. Drag with the RMB to draw a zoom rectangle. Now click with the RMB
to zoom.
4. Wheel / Shift wheel to PAN in the x or y direction
For example if we take a function f(x)=x**3+x
Then the above facts can be executed as
5. Double click on a point to copy its coordinate to the CLIPBOARD. You
can paste back the coordinates to the gnuplot workplace or a text file as
long as it is there on the clipboard
gnuplot> -0.562399, 0.00000
As we can see the coordinates have been copied to clipboard and can be
used in any workspace by simply pressing ctrl v.
6. To mark a point on the graph with its coordinates, Press down with the
wheel on that point. These labels are not permanant; they get lost over a
zooming operation. To place permanent labels say set mouse labels
before pressing down with the wheel Even permanant labels are erasable,
Just keep CTRL pressed while pressing down with the wheel again on the
same point
7. Press ‘r’ over a point to display a vertical ruler at that point. Press ‘r’
again to turn it off. While the ruler is on, the distance in user units from
the ruler origin to the mouse is displayed continuously.
EXERCISE 2
(a) Plot the graph of x^3 + 1 − exp(x) over x = −8 . . . 8. Select suitable y
range to show all the four x intercepts. [Set the zeroaxis, set manually
the yrange to be [-5:5] ]
gnuplot> set yrange[-5:5]
gnuplot> set xrange[-8:8]
gnuplot> f(x)=x**3+1-exp(x)
gnuplot> set zeroaxis
gnuplot> plot f(x)
(b) Plot 3x^4 − 6x^2 over the domain [-10,10] with automatic y scaling.
After observing the graph, edit the domain and range so that you can
see the x-intercepts clearly. Estimate the x-intercepts with the mouse
cursor.
gnuplot> set xrange[-10:10]
gnuplot> f(x)=3*x**4-6*x**2
gnuplot> plot f(x)
the x intercepts are
-1.40120, -0.00859951
1.39857, -0.00859951
(c) Define the functions g(x) = 5 exp(−0.5x) and h(x) = x + 1, then do the
following. Plot a graph that shows both functions g(x) and h(x).
Experiment with different values for domain and range. Estimate the
coordinates of the point of intersection of these two graphs by using
left mouse-button click. Check the answer by any calculator. You can
also use gnuplot ’s print command to check the answer.
g(x)=5*exp(-0.5*x)
gnuplot> h(x)=x+1
gnuplot> plot g(x),h(x)
gnuplot> set xrange[-10:10]
gnuplot> set zeroaxis
gnuplot> plot g(x),h(x)
The approximate value of intersection from the graph is seen to be
0.976724, 4.59459
(d) Define the function k(x) = x + 3 sin(2x). Plot the graph of this function
on the domain [-1,8]. Modify your plot to include the horizontal line y =
4. Use this new plot to estimate the number and approximate values
for x such that k(x) = 4.
gnuplot> k(x)=x+3*sin(2*x)
gnuplot> set xrange[-1:8]
gnuplot> plot k(x)
From the plot we can see that the number of values where k(x)=4 are 3.
They are (3.27111, 3.98624),( 4.85652, 3.98624),( 5.93658, 4.00491).
(e) Plot exp(−x/100) cos x with a suitable sampling rate to plot a smooth
curve. Set the domain to [0:100]. Examine with different sampling rates.
Download