Octave Hints

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Octave Hints as PDF for free.

More details

  • Words: 752
  • Pages: 3
HINTS FOR GETTING STARTED WITH OCTAVE

Michael J. Johnson Spring 2008

Octave Installation and Documentation Octave is a standard package in most linux installations. If you’re using Windows XP, then you can download the file octave-4.1.73-1-inst.xxx from the course repository, rename it as octave-4.1.73-1-inst.exe, and then install it. The repository also contains some supplementary octave functions in files like supp octave function?.tar.gz which is a gzipped archive (good luck extracting that!). The ascii text files contained in the archive have been converted to Dos format (the line endings in Dos are different than Unix), so if you are using Linux, you’ll have to convert them to Unix format with the unix command dos2unix (eg. dos2unix *.m). You can also download the Octave manual octave.pdf from the repository, but keep in mind that you can get help on any particular octave command by typing help commandname at the octave prompt. Getting Started I suggest that you have the Octave manual along with an octave session both running simultaneously on your machine. In order to start Octave under linux, you should open a terminal (or console) and type the command octave I suggest that you read the sections Preface and Introduction and work the suggested examples so that you can get some quick experience. In the introduction, you can skip the part about integrating diffierential equations and obtaining graphical output. Getting familiar with important commands As a first task, I suggest that you try to learn how do plots. For this you’ll need to read about the Octave commands linspace and plot. You can find linspace in the function index of the Octave manual. The command plot can be found in the section Plotting. For a quick and short explanation, you use the Octave command help linspace or help plot. Here’s a sample to give you a quick idea (but be sure to read the documentation!): N=10; x=linspace(0,6,N); Typeset by AMS-TEX

1

2

HINTS FOR GETTING STARTED WITH OCTAVE

y=sin(x); plot(x,y); (Note: using N=1000 will give you a more accurate plot) I suggest that you try to become familiar with the following Octave commands (see function index of manual): linspace, plot, rand, size, length, zeros, ones, eye, abs, max, min, sort, who After this, have a look at Expressions -> Arithmetic Operators to understand the operators + − ∗ / ∧ \ .∗ ./ .∧ The first four operators above are straightforward; while the last four are very useful, but require some thought and experimentation to understand. As an example problem, try to plot the function f (x) =

sin(x3 ) , 1 + cos2 (x)

0 ≤ x ≤ 2π

( in Octave, pi = π).

Next, have a look at the Polynomial Manipulations section of the Octave manual with special attention given to the Octave commands polyval, conv, polyderiv, polyinteg. You can try the following problem: Example. Let f (x) = x3 − 2x + 1 and g(x) = 3x + 2, 0 ≤ x ≤ 2. a) Plot f b) Construct and plot h = f g. R c) Construct and plot k = f 0 + g. R2 d) Find 1 f (x) dx. e) Construct and plot p = f + g (be careful: f and g have different degrees!) Note: you’re supposed to use Octave to do everything here; don’t multiply, integrate, or differentiate by hand. Lastly, please read Functions and Scripts -> Script Files to learn how to write script files. When you use Octave to solve homework problems you’ll have to write your solution as a script file and give it to me on a diskette or via email. Under Linux, I suggest the text editor gedit which is similar to Bill Gate’s program notepad. You start it at the command prompt (ie inside a terminal) with the command: gedit & (the optional & keeps your terminal alive while gedit is running)

CS-543

3

Using diskettes with Linux In order to use a diskette under linux, you first insert the diskette and then give the command mount /mnt/floppy To copy the file hw1.m from your current directory to the diskette, use the command cp hw1.m /mnt/floppy To copy the file script1.m from the diskette to your current directory, use the command cp /mnt/floppy/script1.m . To remove the file hw2.m from the diskette, use the command rm /mnt/floppy/hw2.m Before removing the diskette, you should give the command umount /mnt/floppy to ensure that the computer is finished writing to or reading from the diskette when you remove it.

Related Documents

Octave Hints
November 2019 35
Hints
October 2019 15
Octave
December 2019 41
My Hints
November 2019 9
Tsl Hints
November 2019 18
Manual Octave
July 2020 14