Book a Demo
Prev Next

Getting Started with Solvers

The Solver Class variable can be created once per simulation or, if required, multiple Solver Class instances can be created. Note that starting a new Solver Class instance can sometimes take many seconds. It is generally recommended to create one Solver instance at the start of the simulation and reuse it when required.

To use the Solver Class, you need to have a knowledge of the functions available in your preferred Math Library and the parameters they use, as described in the Library product documentation.

You first define the Math Library (or libraries) that you intend to use in your script. For MATLAB you type:

     var matlab = new Solver('matlab');

For Octave you type:

     var octave = new Solver('octave');

Then, wherever you need to use a maths function within your script, for MATLAB you type:

     matlab.exec('complexMathsFunction', parameters);

For Octave, you type:

     octave.exec('complexMathsFunction', parameters);

These two lines of script execute the function within the appropriate tool and display the results there. If you want to bring the results back into Enterprise Architect, you precede the line with:

     var resultFrom'Toolname';

That is:

     var resultFromMatlab = matlab.exec('complexMathsFunction', parameter1, parameter2);        or

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

Being part of the JavaScript engine, the Solver Classes are also immediately accessible to Add-In writers creating model-based JavaScript Add-Ins.

Note: If a new Solver is created in a section of JavaScript that is called multiple times, simulation performance will be greatly decreased (for example, on a StateMachine node that is entered multiple times).

See the GNU Octave Solver and MATLAB Solver Help topics for further information on these two Solvers.

Solver Constructor

Constructor

Description

See also

Solver(string solverName)

Creates a new Solver connected to a new instance of the specified helper application.

Solver Methods

Method

Description

See also

get(string name)

Retrieves a named value from within the solver environment.

set(string name, object value)

Assigns a new value to a named variable in the solver environment.

exec(string name, string arguments, int returnValues)

Executes a named function. The actual functions will depend on the type of solver being used.

Learn more