12.07.2015 Views

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

100 <strong>GNU</strong> <strong>Octave</strong>source (file)Built-in FunctionParse and execute the contents of file. This is equivalent to executing commands froma script file, but without requiring the file to be named ‘file.m’.13.8 Dynamically Linked FunctionsOn some systems, <strong>Octave</strong> can dynamically load and execute functions written in C++.<strong>Octave</strong> can only directly call functions written in C++, but you can also load functionswritten in other languages by calling them from a simple wrapper function written in C++.Here is an example of how to write a C++ function that <strong>Octave</strong> can load, with commentary.The source for this function is included in the source distributions of <strong>Octave</strong>, in thefile ‘examples/oregonator.cc’. It defines the same set of differential equations that areused in the example problem of Section 23.1 [Ordinary Differential Equations], <strong>page</strong> 189.By running that example and this one, we can compare the execution times to see whatsort of increase in speed you can expect by using dynamically linked functions.The function defined in ‘oregonator.cc’ contains just 8 statements, and is not muchdifferent than the code defined in the corresponding M-file (also distributed with <strong>Octave</strong> inthe file ‘examples/oregonator.m’).Here is the complete text of ‘oregonator.cc’:just#include DEFUN_DLD (oregonator, args, ,"The ‘oregonator’."){ColumnVector dx (3);ColumnVector x (args(0).vector_value ());dx(0) = 77.27 * (x(1) - x(0)*x(1) + x(0)- 8.375e-06*pow (x(0), 2));dx(1) = (x(2) - x(0)*x(1) - x(1)) / 77.27;dx(2) = 0.161*(x(0) - x(2));return octave_value (dx);}The first line of the file,#include includes declarations for all of <strong>Octave</strong>’s internal functions that you will need. If you needother functions from the standard C++ or C libraries, you can include the necessary headershere.The next two linesDEFUN_DLD (oregonator, args, ,"The ‘oregonator’.")

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!