------------------------------------------------------------------------- PHYS210 2009-10-27 LAB SUMMARY 1) The ~/.octaverc file (octave start-up file) 2) Octave "core files" 3) Simple 2D plotting with octave 4) Lab assignment (see handout) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1) The ~/.octaverc file (octave start-up file) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- Commands in the hidden file ~/.octaverc are executed every time octave starts. This is a convenient place to add components to octave's path, i.e. to the list of directories in which it will search for function and script .m files Change to your home directory, and using your text editor create the file .octaverc so that it contains the lines between the -------'s below % cd % [kate, gedit, xemacs, vi, ...] .octaverc ------------------------------------------------------------------------ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Start-up file for octave %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Add path components addpath('~/octave'); addpath('/home/phys210/octave'); addpath('/home/phys210/octave/hw3'); ------------------------------------------------------------------------ Now, start octave (>> stands for the octave prompt) % octave and type greetings >> greetings A message such as the following should appear Greetings, user phys210t! 'greetings' is a octave function defined in the ~phys210/octave, and you can see its definition (as well as verifying the location of the source file) using the 'type' command (this works for all MATLAB / octave function, although no octave code is displayed for built-in functions) >> type greetings greetings is the user-defined function defined from: /home/phys210/octave/greetings.m function [] = greetings() fprintf('Greetings, user %s!\n',getenv('LOGNAME')); end ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2) Octave "core files" ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- From time to time octave may terminate abnormally, particularly if you use Ctrl-C to interrupt a calculation that is taking an inordinately long time. In such instances, octave may 'dump core'---i.e. write a memory image to a file that, in principle, can later be loaded into octave to resume the computation. In most cases, however, you will not want to use this resume feature, and the file that is produced (which always has the name octave-core) can be quite large. Thus, if you notice an 'octave-core' file while working with octave, it is best to remove it. Also, there is an octave function, octave_core_file_limit, which can be used to control the size of the core file. Recommended practice, then (unless you really think you can make use of the restore feature), is to put the following line in your ~/.octaverc octave_core_file_limit(1.0e-10); which will limit the size of octave-core to a few bytes. Note that octave_core_file_limit(0) doesn't do what you might expect, and in fact generates an error message. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3) Simple 2D plotting with octave ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Ensure that you are in your ~/octave directory, start up octave and execute 'plotex' % cd ~/octave % octave >> plotex You should see output such as the following on your terminal, and, as the script executes, you should also see various plots appearing in a separate plotting window labelled 'Figure 1'. If this doesn't work for you, ask for help. The following is a plot of sin(x)*sin(3x) for 0 <= x <= 2 pi, and using - 1000 points uniformly distributed in the interval - default plotting style (line) - default line color - default annotations (no title, axes labels or legend) Type 'Enter' to continue: The following is a plot of sin(x)*sin(3x) for 0 <= x <= 2 pi, using - 1000 points uniformly distributed in the interval - points plotting style, with small green circles for the points - a title and axes labels Type 'Enter' to continue: The following is a plot of sin(x)*sin(3x) AND cos(5x)*cos(2x) for 0 <= x <= 2 pi, using - 1000 points uniformly distributed in the interval - red +'s for the first data set, a cyan line for the second - a title, axes labels and legend Also, a hardcopy of the figure is saved as 'plot.ps' You should see 'plot.ps' in the following listing of the current directory hello.m probs1.m probs2.m Probs3.m threeoutargs.m t_threeoutargs.m plot.ps Probs1.m Probs2.m sintaylor.m t_sintaylor.m Once you have finished with this demo, study the script file /phys210/octave/plotex.m to see how the plots were generated. You can use this file as a template to work from for today's assignments, as well as current and upcoming homework, your term projects etc. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4) Lab assignment (see handout) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++