Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
GNU Octave Beginner's Guide

You're reading from   GNU Octave Beginner's Guide Become a proficient Octave user by learning this high-level scientific numerical tool from the ground up

Arrow left icon
Product type Paperback
Published in Jun 2011
Publisher Packt
ISBN-13 9781849513326
Length 280 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jesper Schmidt Hansen Jesper Schmidt Hansen
Author Profile Icon Jesper Schmidt Hansen
Jesper Schmidt Hansen
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

GNU Octave
Credits
About the Author
About the Reviewers
1. www.PacktPub.com
2. Preface
1. Introducing GNU Octave FREE CHAPTER 2. Interacting with Octave: Variables and Operators 3. Working with Octave: Functions and Plotting 4. Rationalizing: Octave Scripts 5. Extensions: Write Your Own Octave Functions 6. Making Your Own Package: A Poisson Equation Solver 7. More Examples: Data Analysis 8. Need for Speed: Optimization and Dynamically Linked Functions Pop quiz - Answers

Time for action - testing with peaks


  1. 1. You can enter the interactive environment by typing octave in your shell under GNU/Linux, or by double-clicking the Octave icon in Windows. You should now see the Octave prompt:

octave:1>
  1. 2. You have already learned how to exit the interactive environment. Simply give Octave the command exit or press Ctrl + D, but we do not want to exit just yet!

  2. 3. At the prompt, type as follows:

octave:1> surf(peaks)
  1. 4. You should now see a three-dimensional surface plot as depicted on the left-hand side figure shown next. If not, your installation has not been successful. Now, put your mouse pointer over the figure window, hold the left mouse button down, and move the pointer. If the plotting program supports it, the figure should now rotate in the direction you move the pointer. If you click on the figure window using mouse button three (or the scroll wheel) you can zoom by moving the pointer side to side or up and down.

  2. 5. Let us try a contour plot. Type as follows:

octave:2> contourf(peaks)
  1. 6. Does it look like the following figure on the right? If not, it can be because you are using Octave version 3.2.4 and have the package oct2mat loaded. Try typing

octave:3> pkg unload oct2mat
  1. 7. Now retype the previous command.

  2. 8. Click somewhere on the window of the right-hand side figure with button three. A cross and two numbers appear in the window if you are using gnuplot with Octave. The cross is just the point where you clicked. The two numbers show the x axis and y axis values.

Note

Octave can use different plotting program, for example, gnuplot or its own native plotting program. Therefore, your figures may look a bit different, depending on that program.

What just happened?

The figure to the left shows a graph of a mathematical function, which is a scalar function of two variables y and x given by:

(1.1)

The function value (range) is evaluated in Octave by the command peaks, which is the nick name for the function f. The graph is then plotted using the Octave function surf. As a default, Octave calculates the range of f using 50 x and y values in the interval [ 3; 3]. As you might have guessed already, the contourf Octave function plots the contours of f. Later we will learn how to label the axis, add text to the figures, and much more.

Did you notice the phrase "Octave function" previously? An Octave function is not necessarily a mathematical function as Equation (1.1), but can perform many different types of operations and have many different functionalities. Do not worry about this for now. We will discuss Octave functions later in the book.

Notice that the interpreter keeps track of the number of commands that have been entered and shows this at the prompt.

You have been reading a chapter from
GNU Octave Beginner's Guide
Published in: Jun 2011
Publisher: Packt
ISBN-13: 9781849513326
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime