HyperMath

Registering HyperMath Functions with HyperWorks Products

Registering HyperMath Functions with HyperWorks Products

Previous topic Next topic No expanding text in this topic  

Registering HyperMath Functions with HyperWorks Products

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

HyperMath functions are directly supported by HyperWorks Desktop and HyperStudy, making the registered HyperMath functions accessible in those products.  There are two ways to register the functions as shown below.

NoteThe HyperMath function must return a scalar or a vector. And the .HML file can only contain functions (no code outside functions)

Automatic Registration via the HyperMath Graphical User Interface

This method allows you to register HyperMath functions with HyperGraph or HyperStudy.  To register a written function, make sure it is saved on disk.  In the HyperMath editor, select the function signature and right-click and select Register with HyperGraph/HyperStudy… from the context-sensitive menu.

register_hm_fnc_with_hwd

This displays a dialog listing the function name, the number of inputs, and the .hml file location.  To complete the registration with HyperGraph or HyperStudy, simply accept the dialog.

NoteThe dialog also displays all pre-existing functions registered with HyperGraph or HyperStudy via this mechanism.  It also allows you to edit and remove the items.

register_hm_fnc_hwx_dialog

Finally, launch HyperGraph or HyperStudy and the function is automatically loaded in it.

Manual Registration via a Preference File

This method allows you to register a function by manually creating a preference file and explicitly registering it with HyperWorks Desktop.  After registering an .hml file with *RegisterHMATHFunction() in a HyperWorks preference file, the HyperMath functions in the file are available, just like any internal math function.  The registered HyperMath functions are accessible in the following applications: HyperStudy (response functions), TextView, HyperView (notes), HyperGraph (curves, notes, datum lines and plot labels), and Templex.

The syntax for the registration keyword is:

*RegisterHMATHFunction(Function, File, Parameters)

Where:

Option

Description

Function

The name of the HyperMath function.  This is a string.

File

The name of the HML file where the above function resides.  This is a string.

Parameters

The number of parameters the function accepts as inputs.  This is for syntax presentation only.

An example with fixed number of Parameters:

*RegisterHMATHFunction("Addition", "c:/hmath/MyFile.hml", 2); where Addition is the function in the MyFile.hml and that function takes two arguments as input.

The file MyFile.hml could look like this:

function Addition (a,b)   // Addition is the function & a,b are the two arguments

    c = a+b;

return (c)

end

An example with a variable number of Parameters:

*RegisterHMATHFunction("Addition_var", "c:/hmath/MyFile.hml", 1); where Addition_var is the function in the MyFile.hml and that function takes variable number arguments as input, even though one argument is defined in the preference file.

The file MyFile.hml could look like this:

function Addition_var (...)   // Note the three dots constitute variable number of arguments

 num = arg.n     //number of arguments passed to the function

 i = 1;

 d = 0;

while (i <= num) {

d = arg[i]+d;

i = i+1;

}

return (d)

end

Any time this function is called in HyperGraph or any other program, you will need to manually separate multiple arguments with a comma. For example:

For three arguments: Addition_var(a,b,c)

For four arguments: Addition_var(a,b,c,d) and so on.