# [Mma] someone asked me how to create a file and run it

Boud Roukema boud at astro.uni.torun.pl
Tue Apr 1 14:56:27 CEST 2003

# create a file, in some directory  e.g.
#
# /home2/<myname>/octave/eg_octave.m
#
#
# in octave, type
#
#
# to see the "path" for "loading" files. This is a useful linux/unix concept.
# Then add your path to the beginning or end of the path.
#
#
# type
# to check the new value
#
# WARNING: Do not forget the ":" or you may lose access to libraries!!
#
# to your file ~/.octaverc  so that it is read automatically when you
# start octave.
#
#

# make a 200x200 matrix filled with a random "normal" (gaussian) distribution
# of points with a mean of zero and a standard deviation of about one

x=randn(200,200);

gplot x;  # simply line plot joining these points

bar(x(1:200,1))  # a histogram of the first column

## Question: Is this really a Gaussian distribution of \sigma = 1 ??

# a histogram of the first column, in 10 bins, with a total integral
# of 1.0 * binwidth
hist(x(1:200,1),10,1.0)

# looks like about 68% of integral is within (-1,1), but... let's check

x3=linspace(-4,4,32+1) # make regular bin centres spaced by 0.25
replot
hist(x(1:200,1),x3,1.0/0.25)

# make an xx axis
xx=linspace(-4,3,100);

y3=[]
for i=1:100
y3 = [y3, 1/sqrt(2.0*pi) * exp(- xx(i)*xx(i)/(2.0*1.0*1.0))];
endfor

#      Tell Octave to hold' the current data on the plot when executing
#     subsequent plotting commands.  This allows you to execute a series
#     of plot commands and have all the lines end up on the same figure.
#     The default is for each new plot command to clear the plot device
#     first.  For example, the command
hold on

# create a matrix with first col vector the xx values, 2nd col vector y3
y4= [xx',y3'];

# make the plot
gplot y4

`