Information Technology Reference
In-Depth Information
Heun's method for du/dt = -u
1
u(t)
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
0.5
1
1.5
2
2.5
3
3.5
4
Fig. 6.1
Plot made by Gnuplot
Normally, we want to set a heading in the plot and also produce a hardcopy of
the plot in PostScript format (for inclusion in reports). The following set of Gnuplot
commands perform these tasks:
set title "Heun's method for du/dt = -u"
# plot on the screen:
plot 'sol.dat' title 'u(t)' with lines
# hardcopy in PostScript format:
set term postscript eps monochrome dashed 'Times-Roman' 20
set output 'tmp.ps'
plot 'sol.dat' title 'u(t)' with lines
We recommend putting such commands in a file, say plot , and executing Gnuplot
with the name of this file as the argument:
unix> gnuplot -persist plot
The -persist option makes the plot stay on the screen after the Gnuplot program
has terminated. The PostScript version of the plot is displayed in Fig. 6.1 .
Matlab
Having the x i values as a vector x and the y i values as a vector y , plotting in Matlab
is easily done through the standard command plot(x,y) . In our example with u .t /
data, the following Matlab commands create a plot of the data in the file sol.dat
and annotate a title and curve label, in addition to making a hardcopy of the plot:
data = load('sol.dat'); % load file into two-dim. array data
t = data(:,1); u = data(:,2); % extract columns as vectors
plot(t, u);
 
Search WWH ::




Custom Search