

QEX Aug/Sep 2011	Octave for Curve Fitting    Maynard Wright, W6PAP


      The program needed to execute "Plot_Antenna_Reactance.m" "Plot_Input_Impedance_of_Trans_Line_To_Dipole.m" "Plot_Least_Squares_Antenna_Reactance.m" and "Fit_and_Plot_Sine_Wave.m" is Octave and it can be downloaded for various operating systems, including Windows and Linux, from sites accessible at www.octave.org. Octave is also available with some Linux distributions, as in the Ubuntu and Kubuntu repositories.
      You can start Octave, type code directly into the program at the command prompt and see the results. In addition, Octave, like Matlab, will execute code that resides in text files (Octave script files) that can be edited by any text editor such as Notepad. You can also edit an Octave file in Word, but you must be careful to save it as a text file. Under Linux, there are various text and program editors available: I prefer Kate. 
      The ".m" filename extension is a Matlab convention and folks often use it in Octave, especially if they intend to port code back and forth between Octave and Matlab. In addition, the instructions below assume that a ".m" extension is used. You can actually use any extension you like with Octave. The extension ".o" might be tempting, but as it means something else in Linux, you should probably avoid it. A .txt extension will also work fine.
      With some earlier versions of Octave, it was necessary to type "source" followed by a space, a filename, and ENTER if you were executing an Octave script file with an extension other than ".m." The files included in this .ZIP file are thus text files, and you can examine or edit them with Notepad, Wordpad, Word, or any other editor capable of handling an ASCII text file.
      You can execute the code in an Octave script file in any of several different ways:
      1. If you're using Windows or Linux, you can start Octave from an icon on the desktop (if you've placed one there) and then run the code from within Octave by specifying the filename followed by ENTER at the Octave command prompt. 
      2. You can open a DOS window or Linux shell, type "octave" followed by ENTER and then execute the program from the Octave command prompt as in 1, above. 
      When execution is complete, control will return to the Octave command prompt for both methods.
      Note that in Linux, filenames are case sensitive and the octave executable filename is all lower case. The Octave executable must be in a location available to the current path information for your OS. (You can find the current path by typing path at the command prompt.)
      3. You can run the code from the command line in a DOS window or a Linux shell command prompt by typing "octave" followed by a space, the filename, and ENTER. To make this work, you may have to put the current directory in your PATH variable. When execution is complete, control returns to the DOS command prompt or the Linux shell command prompt rather than to the Octave command prompt. 
      4. The initial line "#! /usr/bin/octave -qf" in the files is ignored as a comment by Windows, but it tells Linux that that Octave should be executed and should run the code in the present file as a script. That allows an Octave script file to be run in Linux by simply typing the filename followed by ENTER at the terminal window command prompt. This makes the script file essentially an executable file from the user's viewpoint. The path above may need to be modified to tell the code where the Octave executable is located, as it may be installed somewhere else in some versions of Linux. When execution is complete, control returns to the Linux shell command prompt rather than to the Octave command prompt. If the current directory is not in your path variable, you may have to prefix the filename of the script file with "./" to allow Octave to find it. 
      I imagine that the instructions above will work with little or no modification on other OS such as Macs, but I don't have any way to try them. I've run the code for the QEX articles under two versions of Octave for Linux and one for Windows 98SE just to check for Murphy's presence. 
      A GUI for Octave, koctave, is available for Linux systems that use the KDE desktop, but I haven't tried it.

      73, Maynard Wright, W6PAP
      
