Book Image

GNU Octave Beginner's Guide

By : Jesper Schmidt Hansen
Book Image

GNU Octave Beginner's Guide

By: Jesper Schmidt Hansen

Overview of this book

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 (15 chapters)
GNU Octave
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface

Time for action - installing additional packages


  1. 1. Before installing a new package, you should check which packages exist already and what their version numbers are. Start Octave, if you have not done so. Type the following:

octave:1> pkg list
  1. 2. You should now see a table with package names, version numbers, and installation directories. For example:

    Package Name | Version | Installation directory --------------------+-----------+------------------------------------ combinatorics | 1.0.6 | /octave/packages/combinatorics-1.0.6

  2. 3. If you have chosen to install all packages in your Windows installation, the list is long. Scroll down and see if the msh package is installed already, and if so, what the version number is. Again, you can press the Q key to return to the prompt.

  3. 4. Now go to the Octave-Forge web page, find the msh package, and click on Details (to the right of the package name). You will now see a window with the package description, as shown in the following figure. Is the package version number higher than the one already installed? (If not, sit back, relax, and read the following just for the fun of it.) The package description also shows that the msh package dependents on the spline package and Octave version higher than 3.0.0. Naturally, you need Octave. However, the spline package may not be installed on your system. Did you see the spline package when you typed pkg list previously? If not, we will need to install this before installing msh. Go back to the main package list and download the msh and the spline packages to your Octave home directory. (By the way, does the spline package have any dependencies?) The downloaded files will be archived and compressed and have extensions .tar.gz. To install the packages, make sure you are in your Octave home directory and type the following:

octave:2> pkg install splines-version-number.tar.gz
  • (If you need it.)

octave:3> pkg install msh-version-number.tar.gz
  1. 5. Make sure that you have downloaded the package files into the Octave home directory.

  2. 6. To check your new package list, type the following:

octave:4> pkg list
  • Package Name | Version | Installation directory ---------------------+------------+----------------------------- combinatorics | 1.0.6 | /octave/packages/combinatorics-1.0.6 msh | 1.0.1 | /home/jesper/octave/msh-1.0.1 splines * | 1.0.7 | /home/jesper/octave/splines-1.0.7

  1. 7. You can get a description of the msh package by typing the following:

octave5:> pkg describe msh
---
Package name:
msh
Short description:
Create and manage triangular and tetrahedral meshes for Finite
Element or Finite Volume PDE solvers. Use a mesh data structure
compatible with PDEtool. Rely on gmsh for unstructured mesh
generation.
Status:
Not loaded
  1. 8. From the status, you can see that the package has not been loaded, which means we cannot use the functionality that comes with the package. To load it, simply type the following:

octave:6> pkg load msh
  1. 9. You should check that it actually has been loaded using pkg describe msh. Naturally, you can also unload the msh package by using the following command:

octave:7> pkg unload msh

Note

If you are using a multi-user system, consult your system administrator before you install your own local packages.

What just happened?

The important points have already been explained in detail. Note that you need to install splines before msh because of the dependencies.

You may find it a bit strange that you must first load the package into Octave in order to use it. The package can load automatically if you install it with the auto option. For example, command 3 can be replaced with the following:

octave:3> pkg install auto msh-version-number.tar.gz

Some packages will automatically load even though you do not explicitly instruct it to do so when you install it. You can force packages not to load using noauto.

octave:3> pkg install noauto msh-version-number.tar.gz

Uninstalling a package

Unistalling a package is just as easy:

octave:8> pkg uninstall msh

Note that you will get an error message if you try to uninstall splines before msh because msh depends on splines.