Prev Next

GNU Octave Solver

GNU Octave is a library of mathematical functions, with a special emphasis on sequences and matrices. You can call each function into a script written in JavaScript.

You can invoke arbitrary mathematical functions from Octave at run time, using a simple construct called a Solver Class, written in JavaScript; a Solver Class for Octave can call into the external Octave tool and link the powerful mathematical functions directly into your running simulation. For example:

     var octave = new Solver(octave);

     var resultFromOctave = octave.exec('complexMathsFunction', parameter1, parameter2);

See the Help topic Solvers in Simulations.

Features include:

  • Calling in vectors, matrices, numbers, and strings from Octave
  • Octave vectors return as JavaScript one-dimensional arrays (and JavaScript one-dimensional arrays return as Octave vectors)
  • Octave matrices return as JavaScript two-dimensional arrays (and JavaScript two-dimensional arrays return as Octave matrices)
  • You can retrieve variable values from Octave using:
         octave.get(<name>)
  • You can call any Octave function with JavaScript values using:
         octave.exec(<name>, [<arguments>], 0/1)
  • All arguments are passed inside a JavaScript array
  • You can also use the result in JavaScript; pass 1 if you want a result, 0 if you do not want a result
  • You can execute any Octave statement using:
         octave.exec("script", <statement>, 0/1)

Octave is available as an alternative to the MATLAB library and can be used in all the same contexts as MATLAB.

Setup and Configuration

After you install Octave, Enterprise Architect will read the location from the registry to provide automatic integration.

Usage

Task

Description

Assigning Values

Use the octave.set command; for example:

     octave.set("simple_value", 3.14);

     octave.set("example_sequence", [0, 1, 2]);

     octave.set("identity",  [[1, 0], [0, 1]]);

Constructing

Within the JavaScript editor, create a new Solver connected to Octave by passing "octave" to the Solver constructor.

     var octave = new Solver("octave");

Retrieving Values

Use the octave.get command; for example:

     var simple_value = octave.get("simple_value");

     var example_sequence = octave.get("example_sequence");

     var identity= octave.get("identity");

Calling Functions

Pass the name of the function as the first argument to Solver.exec.

Pass all the parameters to that function in an array as the second argument.

When you want a value returned by that function inside JavaScript, pass a non-zero value as the third argument. For example:

     var sequence = octave.exec("linspace", [0, 10, 1001],1);

Executing Statements

Pass 'script' as the name for the first argument to Solver.exec.

Pass an entire Octave statement in a string as the second argument.

octave.exec('script', 't = 0:0.1:6.3;');

octave.exec('script','plot (t, cos(t), "-;cos(t);", t, sin(t), "-b;sin(t);");');

Trace()

The Trace(statement) method allows you to print out trace statements at any arbitrary point in your simulation. This is an excellent means of supplementing the Simulation log with additional output information during execution.

The Trace() output is written to the Simulation window.

This is an example of using the Trace() method:

     octave.set('simple_value', 3.14);

     var pi = octave.get('simple_value');

     Trace( "PI = " + pi ); // output that value to the Simulation Window

Videos

Sparx Systems provide a YouTube video of using a Solver to generate a plot with Octave. See:

Learn more