GNU Octave Beginner's Guide Become a profcient Octave user by learning this high-level scientfc numerical tool from the ground up Jesper Schmidt Hansen BIRMINGHAM - MUMBAI GNU Octave Beginner's Guide Copyright © 2011 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmited in any form or by any means, without the prior writen permission of the publisher, except in the case of brief quotatons embedded in critcal artcles or reviews. Every efort has been made in the preparaton of this book to ensure the accuracy of the informaton presented. However, the informaton contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, its dealers, and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark informaton about all of the companies and products mentoned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this informaton. First published: June 2011 Producton Reference: 2150611 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849513-32-6 www.packtpub.com Cover Image by John Quick ([email protected]) Credits Author Project Coordinator Jesper Schmidt Hansen Joel Goveya Reviewers Proofreaders Piotr Gawron Lesley Harrison Kenneth Geisshirt Clyde Jenkins Jordi Gutérrez Hermoso Lynda Sliwoski Acquisiton Editor Indexers Usha Iyer Hemangini Bari Tejal Daruwale Development Editor Monica Ajmera Mehta Roger D'souza Graphics Technical Editor Nilesh R. Mohite Dayan Hyames Producton Coordinator Kruthika Bangera Cover Work Kruthika Bangera About the Author Jesper Schmidt Hansen holds a Ph.D. in sof material science and is currently doing research in the feld of nanofuidics and dynamics at Roskilde University, Denmark. He has been using GNU Octave on a daily basis for many years, both as a student and later as a researcher. The applicatons have varied from solving partal and ordinary diferental equatons, simple data plotng, data generaton for other applicatons, dynamical system investgatons, and advanced data analysis. Firstly, I wish to thank the reviewers. They have been a great help and their many (at tmes overwhelmingly many) comments and hints have improved the manuscript considerably. I have received encouragement and good ideas from everyone at the Department of Science, Systems and Models, Roskilde University. Especially, I want to thank Professor Jeppe Dyre from the Danish Natonal Research Foundaton centre "Glass and Time" for giving me the opportunity to fnish the book in the last phase of the writng. Also, I have found Octave's ofcial mailing list very useful. Unlike many other user groups, there is a very constructve and helpful atmosphere here. I thank everyone who has submited questons and all those that have replied. I now realize that having a one year old child, a full tme job, as well as writng a book is not really an ideal cocktail. I must thank Signe Anthon for her tremendous support and patence during the writng of this book. When I signed the contract with Packt Publishing, I was happy fnally to be able to make a contributon to the open source community—Signe's contributon is just as big as mine! About the Reviewers Piotr Gawron is a researcher in the feld of quantum informaton processing. His main research topics are quantum programming languages, quantum game theory, and numerical and geometrical methods in quantum informaton. He works in the Quantum Computer Systems Group of the Insttute of Theoretcal and Applied Informatcs of the Polish Academy of Sciences in Gliwice, Poland. Apart from research in theoretcal aspects of computer science, he has gained practcal experience in FPGA development and real-tme image processing for applicatons in UAVs working closely with the industry. He is administrator of www.quantiki.org , a portal for the quantum informaton community. He is a user and strong supporter of free sofware. He likes hard science-fcton literature, live-acton role- playing, and French rock music. Kenneth Geisshirt is a chemist by educaton and a geek by nature. He has been programming for more than 25 years—the last 6 years as a subcontractor. In 1990, Kenneth frst met free sofware, and in 1992 turned to Linux as his primary operatng system (ofcially Linux user no. 573 at the Linux Counter). He has writen books about Linux, PAM, and JavaScript—and many artcles on open source sofware for computer magazines. Moreover, Kenneth has been a technical reviewer of books on Linux network administraton, the Vim editor, and JavaScript testng. Jordi Gutérrez Hermoso studied mathematcs in Canada and Mexico, both pure and applied respectvely. He has been programming since the age of seven, when he started to learn about computers while writng silly programs in BASIC. He has been a Debian user since 2001, his frst and stll preferred GNU/Linux distributon, to which he now occasionally contributes with GNU Octave packaging. Since 2005, he has been an enthusiastc Octave user and started getng more involved with its development in 2010. As of 2011, he resides in Mexico and works in BlueMessaging, where he's responsible for natural language processing and artfcial intelligence. An Emacs user at heart, Jordi feels at home in a GNU environment and will gladly share .emacs confguratons with anyone who asks. I would like to thank my close friends and family for helping me get through difcult tmes and for celebratng the good ones with me. John W. Eaton, Octave's creator, deserves much recogniton for startng and leading the project on which this book is based. www.PacktPub.com Support fles, eBooks, discount offers and more You might want to visit www.PacktPub.com for support fles and downloads related to your book. Did you know that Packt ofers eBook versions of every book published, with PDF and ePub fles available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are enttled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collecton of free technical artcles, sign up for a range of free newsleters, and receive exclusive discounts and ofers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutons to your IT questons? PacktLib is Packt's online digital book library. Here, you can access, read, and search across Packt's entre library of books. Why Subscribe? Fully searchable across every book published by Packt Copy and paste, print, and bookmark content On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entrely free books. Simply use your login credentals for immediate access. Table of Contents Preface 1 Chapter 1: Introducing GNU Octave 7 So what is GNU Octave? 7 Applicatons 9 Limitatons of Octave 9 Octave and MATLAB 10 The Octave community 10 Installing Octave 11 Windows 11 GNU/Linux 12 Building Octave from the source under GNU/Linux 14 Time for acton – building Octave from source 14 Checking your installaton with peaks 15 Time for acton – testng with peaks 15 Customizing Octave 17 Time for acton – creatng an Octave home directory under Windows 18 Creatng your frst .octaverc fle 19 Time for acton – editng the .octaverc fle 19 More on .octaverc 20 Installing additonal packages 21 Time for acton – installing additonal packages 21 Uninstalling a package 23 Getng help 23 The behaviour of the Octave command prompt 24 Summary 24 Chapter 2: Interactng with Octave: Variables and Operators 25 Simple numerical variables 26 Accessing and changing array elements 28 More examples 29 Table of Contents Time for acton – manipulatng arrays 30 Complex variables 31 Text variables 32 Higher-dimensional arrays 34 Structures and cell arrays 35 Structures 35 Time for acton – instantatng a structure 36 Accessing structure felds 37 Cell arrays 39 Time for acton – instantatng a cell array 39 Getng informaton 41 Time for acton – using whos 41 Size, rows, columns, and length 42 Identfying the variable type 43 Deletng variables from the workspace 44 A few things that make life easier 45 Basic arithmetc 47 Additon and subtracton 47 Time for acton – doing additon and subtracton operatons 47 Matrix multplicaton 49 Time for acton – doing multplicaton operatons 49 Element-by-element, power, and transpose operatons 50 Operators for structures and cell arrays 52 Solving linear equaton systems: lef and right division 52 Time for acton – doing lef and right division 53 Basic arithmetc for complex variables 55 Summary of arithmetc operators 57 Comparison operators and precedence rules 58 Precedence rules 60 Time for acton – working with precedence rules 60 A few hints 61 Summary 63 Chapter 3: Working with Octave: Functons and Plotng 65 Octave functons 65 Mathematcal functons 66 Time for acton – using the cos functon 66 Polynomials in Octave 68 More complicated mathematcal functons 69 Time for acton – putng together mathematcal functons 70 Helper functons 71 Generatng random numbers 72 min and max 72 [ ii ] Table of Contents Sortng arrays 73 fnd, any, and all 74 foor, ceil, round, and fx 75 Time for acton – trying out foor, ceil, round, and fx 75 sum and prod 76 Absolute values 77 Complex input arguments 77 Operator functons 78 Linear algebra 78
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages280 Page
-
File Size-