GNU Octave

Book description

Become a proficient Octave user by learning this high-level scientific numerical tool from the ground up

  • The easiest way to use GNU Octave's power and flexibility for data analysis
  • Work with GNU Octave's interpreter – declare and control mathematical objects like vectors and matrices
  • Rationalize your scripts and control program flow
  • Extend GNU Octave and implement your own functionality
  • Get to know the vast built-in functionality that GNU Octave has to offer
  • Build your own GNU Octave toolbox package to solve complex problems
  • Learn Octave the simple way, with real-world examples and plenty of screenshots provided throughout the book

In Detail

Today, scientific computing and data analysis play an integral part in most scientific disciplines ranging from mathematics and biology to imaging processing and finance. With GNU Octave you have a highly flexible tool that can solve a vast number of such different problems as complex statistical analysis and dynamical system studies.

The GNU Octave Beginner's Guide gives you an introduction that enables you to solve and analyze complicated numerical problems. The book is based on numerous concrete examples and at the end of each chapter you will find exercises to test your knowledge. It's easy to learn GNU Octave, with the GNU Octave Beginner's Guide to hand.

Using real-world examples the GNU Octave Beginner's Guide will take you through the most important aspects of GNU Octave. This practical guide takes you from the basics where you are introduced to the interpreter to a more advanced level where you will learn how to build your own specialized and highly optimized GNU Octave toolbox package. The book starts by introducing you to work variables like vectors and matrices, demonstrating how to perform simple arithmetic operations on these objects before explaining how to use some of the simple functionality that comes with GNU Octave, including plotting. It then goes on to show you how to write new functionality into GNU Octave and how to make a toolbox package to solve your specific problem. Finally, it demonstrates how to optimize your code and link GNU Octave with C and C++ code enabling you to solve even the most computationally demanding tasks. After reading GNU Octave Beginner's Guide you will be able to use and tailor GNU Octave to solve most numerical problems and perform complicated data analysis with ease.

Table of contents

  1. GNU Octave
    1. Table of Contents
    2. GNU Octave
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Time for action – heading
        1. What just happened?
        2. Pop quiz – heading
        3. Have a go hero – heading
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Introducing GNU Octave
      1. So what is GNU Octave?
        1. Applications
        2. Limitations of Octave
        3. Octave and MATLAB
        4. The Octave community
      2. Installing Octave
        1. Windows
        2. GNU/Linux
          1. Building Octave from the source under GNU/Linux
      3. Time for action – building Octave from source
        1. What just happened?
      4. Checking your installation with peaks
      5. Time for action – testing with peaks
        1. What just happened?
      6. Customizing Octave
      7. Time for action – creating an Octave home directory under Windows
        1. What just happened?
        2. Creating your first .octaverc file
      8. Time for action – editing the .octaverc file
        1. What just happened?
        2. More on .octaverc
      9. Installing additional packages
      10. Time for action – installing additional packages
        1. What just happened?
        2. Uninstalling a package
      11. Getting help
      12. The behaviour of the Octave command prompt
      13. Summary
    9. 2. Interacting with Octave: Variables and Operators
      1. Simple numerical variables
        1. Accessing and changing array elements
          1. More examples
      2. Time for action – manipulating arrays
        1. What just happened?
        2. Complex variables
        3. Text variables
        4. Higher-dimensional arrays
        5. Pop Quiz – working with arrays
      3. Structures and cell arrays
        1. Structures
      4. Time for action – instantiating a structure
        1. What just happened?
        2. Accessing structure fields
        3. Cell arrays
      5. Time for action – instantiating a cell array
        1. What just happened?
        2. Have a go hero – working with structures
      6. Getting information
      7. Time for action – using whos
        1. What just happened?
        2. Size, rows, columns, and length
        3. Identifying the variable type
        4. Deleting variables from the workspace
        5. Pop Quiz – understanding arrays
      8. A few things that make life easier
      9. Basic arithmetic
        1. Addition and subtraction
      10. Time for action – doing addition and subtraction operations
        1. What just happened?
        2. Matrix multiplication
      11. Time for action – doing multiplication operations
        1. What just happened?
        2. Element-by-element, power, and transpose operations
        3. Operators for structures and cell arrays
        4. Solving linear equation systems: left and right division
      12. Time for action – doing left and right division
        1. What just happened?
        2. Basic arithmetic for complex variables
        3. Summary of arithmetic operators
        4. Pop Quiz – understanding simple operations
        5. Have a go hero – doing the dot product
      13. Comparison operators and precedence rules
        1. Precedence rules
      14. Time for action – working with precedence rules
        1. What just happened?
        2. Pop Quiz – understanding precedence rules
      15. A few hints
      16. Summary
    10. 3. Working with Octave:Functions and Plotting
      1. Octave functions
        1. Mathematical functions
      2. Time for action – using the cos function
        1. What just happened?
          1. Polynomials in Octave
          2. More complicated mathematical functions
      3. Time for action – putting together mathematical functions
        1. What just happened?
        2. Helper functions
          1. Generating random numbers
          2. min and max
          3. Sorting arrays
          4. find, any, and all
          5. floor, ceil, round, and fix
      4. Time for action – trying out floor, ceil, round, and fix
        1. What just happened?
          1. sum and prod
          2. Absolute values
          3. Complex input arguments
        2. Operator functions
          1. Linear algebra
      5. Time for action – using Octave for advanced linear algebra
        1. What just happened?
          1. Polynomials
        2. Pop Quiz – using simple mathematical functions
        3. Have a go hero – understanding the find function
      6. Two-dimensional plotting
      7. Time for action – making your first plot
        1. What just happened?
          1. plot and set
      8. Time for action – changing the figure properties
        1. What just happened?
          1. Adding lines and text to your plot
          2. Plot styles and colors
          3. Title and legends
          4. Ticks
          5. Grids
          6. fplot
          7. Clear the figure window
        2. Moving on
      9. Time for action – having multiple graphs in the same figure
        1. What just happened?
          1. Multiple figure windows
          2. Subplots
      10. Time for action – making an inset
        1. What just happened?
          1. Saving your plot
        2. Pop Quiz – understanding the plotting options
        3. Have a go hero – making inserts
      11. Three-dimensional plotting
        1. Surface plot
      12. Time for action – making a surface plot
        1. What just happened?
          1. view and colormap
          2. Contour plots
          3. Three-dimensional parametric plots
      13. Time for action – plotting parametric curves
        1. What just happened?
        2. Have a go hero – revisiting peaks
      14. Summary
    11. 4. Rationalizing: Octave Scripts
      1. Writing and executing your first script
      2. Time for action – making your first script
        1. What just happened?
        2. Improving your script: input and disp
      3. Time for action – interacting with the user
        1. What just happened?
          1. Flush please
          2. Comments
          3. Very long commands
          4. Workspace
          5. For GNU/Linux and MacOS X users
        2. Pop Quiz – understanding disp and input
        3. Have a go hero – using scripts for plotting
      4. Statements
        1. Prime numbers
        2. Decision making – the if statement
        3. Interlude: Boolean operators
          1. Element-wise Boolean operators
          2. Short-circuit Boolean operators
          3. Using Boolean operators with an if statement
          4. Nested statements
        4. The switch statement
        5. Loops
          1. The for statement
          2. The while and do statements
            1. Incremental operators
          3. Nested loops
        6. Putting it all together
        7. Exception handling
        8. Pop Quiz – understanding statements and Boolean operators
      5. Added flexibility – C style input and output functions
        1. printf
        2. Pop Quiz – printing with printf
      6. Saving your work
      7. Loading your work
        1. Functional forms
        2. Have a go hero – investigating the prime gab
      8. Summary
    12. 5. Extensions: Write Your Own Octave Functions
      1. Your first Octave function
      2. Time for action – programming the minmax function
        1. What just happened?
        2. Scripts versus functions
        3. Defining functions at the command prompt
        4. Writing a function help text
        5. Checking the function call
          1. The usage, warning, and error functions
          2. nargin and nargout
        6. Pop Quiz – understanding functions
        7. Have a go hero – converting scripts into functions
      3. Writing and applying user-supplied functions
        1. Using fsolve
          1. Providing the Jacobian
        2. Using lsode – dynamical analysis of the Sel'kov model
      4. Time for action – using lsode for numerical integration
        1. What just happened?
        2. Inline functions
        3. Pop Quiz – implementing mathematical functions as Octave functions
        4. Have a go hero – bifurcation in the Sel'kov model
      5. More advanced function programming: Monte Carlo integration
        1. The feval function
        2. Validating the user-supplied function
        3. Using quad and trapz for numerical integration
        4. Vectorized programming
      6. Time for action – vectorizing the Monte Carlo integrator
        1. What just happened?
        2. Simple debugging
        3. Multiple function file
        4. Pop Quiz – understanding vectorization
        5. Have a go hero – using the debugger
      7. Summary
    13. 6. Making Your Own Package: A Poisson Equation Solver
      1. The Poisson equation – two examples of heat conduction
        1. One-dimensional heat conduction
        2. Two-dimensional heat conduction
        3. The Poisson equation
        4. The Dirichlet boundary condition
        5. Pop Quiz – identifying the Poisson equation
      2. Finite differencing
        1. From finite difference to a linear equation system
        2. Interlude: Sparse matrices
      3. Time for action – instantiating a sparse matrix
        1. What just happened?
        2. Memory usage
      4. Implementation and package functions
        1. The coefficient matrix for one dimension
        2. The coefficient matrix for two dimensions
          1. The conversion function
        3. Testing the functions
          1. The coefficient matrices
      5. Time for action – using imagesc
        1. What just happened?
          1. Comparison with analytical solution
      6. Time for action – comparing with analytical solution
        1. What just happened?
          1. Two dimensions
      7. Time for action – solving a two-dimensional Laplace equation
        1. What just happened?
        2. More examples
        3. Wrapping everything into one function
        4. Have a go hero – optimizing the usage of the sparse function
      8. The pois-solv package
        1. Organizing files into the package directory
          1. The DESCRIPTION file
          2. The COPYING file
          3. The INDEX file
        2. Building the package
        3. Limitations and possible extensions to the package
      9. Summary
    14. 7. More Examples: Data Analysis
      1. Loading data files
      2. Simple descriptive statistics
        1. Histogram and moments
        2. Sample moments
        3. Comparing data sets
          1. The correlation coefficient
          2. The student t-test
      3. Function fitting
        1. Polynomial fitting
      4. Time for action – using polyfit
        1. What just happened?
          1. Goodness of the fit
      5. Time for action – calculating the correlation coefficient
        1. What just happened?
          1. Residual plot
        2. Non-polynomial fits
          1. Transforms
          2. General least squares fitting
            1. Time for action – using leasqr
              1. What just happened?
              2. Have a go hero – calculating the deviation of the Monte Carlo integrator
            2. Fourier analysis
              1. The Fourier transform
            3. Time for action – using the fft function
              1. What just happened?
                1. Fourier analysis of currency exchange rate
            4. Time for action – analysing the exchange rate
              1. What just happened?
              2. Inverse Fourier transform and data smoothing
                1. The Butterworth filter
            5. Time for action – applying a low pass filter
              1. What just happened?
              2. Have a go hero – implementing your own Fourier transform function
            6. Summary
    15. 8. Need for Speed: Optimization and Dynamically Linked Functions
      1. A few optimization techniques
        1. tic, toc
      2. Time for action – using tic and toc
        1. What just happened?
        2. Vectorization
        3. Initialization of variables
        4. Looping row-wise versus looping column-wise
        5. Have a go hero – revision of cmat_1d
      3. Dynamically linked functions
        1. The DEFUN_DLD function macro
      4. Time for action – writing a "Hello World" program
        1. What just happened?
        2. Managing input arguments and outputs
      5. Time for action – checking user inputs and outputs
        1. What just happened?
          1. Retrieving the inputs
          2. Class types
        2. Functions as input argument
        3. Optimization with oct-files
      6. Time for action – revisiting the Sel'kov model
        1. What just happened
        2. Have a go hero – implementing the Euler integrator
      7. Summary
    16. A. Pop Quiz Answers
      1. Chapter 2: Interacting with Octave: Variables and Operators
        1. Working with arrays
        2. Understanding arrays
        3. Understanding simple operations
        4. Understanding precedence rules
      2. Chapter 3: Working with Octave: Functions and Plotting
        1. Using simple mathematical functions
        2. Understanding the plotting options
      3. Chapter 4: Rationalizing: Octave Scripts
        1. Understanding disp and input
        2. Understanding statements and Boolean operators
        3. Printing with printf
      4. Chapter 5: Extensions: Write Your Own Octave Functions
        1. Understanding functions
        2. Implementing mathematical functions as Octave functions
        3. Understanding vectorization
      5. Chapter 6: Making Your Own Package: A Poisson Equation Solver
        1. Identifying the Poisson equation
    17. Index

Product information

  • Title: GNU Octave
  • Author(s): Jesper Schmidt Hansen
  • Release date: June 2011
  • Publisher(s): Packt Publishing
  • ISBN: 9781849513326