Metabase: Object;
Metabase: object;
The Metabase property determines the repository where the system searches for the custom unit used in the expression.
This property is relevant for statistical methods, for which the expressions can be specified:
Executing the example requires that the repository contains a unit with the STAT_FUNC identifier containing the "test" custom function.
Add links to the Metabase, Stat system assemblies.
Sub UserProc;
Var
sm: SmNonLinearEquations;
functions: array[2] Of string;
initvalues: array[2] Of double;
status: integer;
provider: ISmExpressionProvider;
Begin
sm := New SmNonLinearEquations.Create;
provider := sm As ISmExpressionProvider;
// Get the current repository for searching for a custom unit
provider.Metabase := MetabaseClass.Active;
// Set equation expressions
functions[0] := "y1+12.34-0.21*134";
// Pass custom function to equation expression
functions[1] := "STAT_FUNC.test(y1,y2)";
sm.Functions := functions;
initvalues[0] := 1;
initvalues[1] := 1;
// Determine initial approximations
sm.InitApproximation := initvalues;
// Determine coefficient order
sm.CoefficientsOrder := "y1;y2";
// Check if there are errors
status := sm.Execute;
debug.WriteLine(status);
debug.WriteLine(sm.Errors);
If (status = 0) Then
debug.WriteLine(sm.Solution[0].tostring);
debug.WriteLine(sm.Solution[1].tostring);
debug.WriteLine(sm.FunctionValues[0].tostring);
debug.WriteLine(sm.FunctionValues[1].tostring);
End If;
End Sub UserProc;
// Custom function
Public Function test(x1, x2: double): double;
Begin
Return x1 * (x2 - 1);
End Function test;
Executing this example shows the calculation results in the console window: Custom function is to be used in method expressions.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
sm: SmNonLinearEquations;
functions: array[2] Of string;
initvalues: array[2] Of double;
status: integer;
provider: ISmExpressionProvider;
Sol, Func: System.Array;
Begin
sm := New SmNonLinearEquations.Create();
provider := sm As ISmExpressionProvider;
// Get the current repository for searching for a custom unit
provider.Metabase := Params.Metabase;
// Set equation expressions
functions[0] := "y1+12.34-0.21*134";
// Pass custom function to equation expression
functions[1] := "STAT_FUNC.test(y1,y2)";
sm.Functions := functions;
initvalues[0] := 1;
initvalues[1] := 1;
// Determine initial approximations
sm.InitApproximation := initvalues;
// Determine coefficient order
sm.CoefficientsOrder := "y1;y2";
// Execute calculation
status := sm.Execute();
System.Diagnostics.debug.WriteLine(status);
System.Diagnostics.debug.WriteLine(sm.Errors);
If (status = 0) Then
Sol := sm.Solution;
Func := sm.FunctionValues;
System.Diagnostics.debug.WriteLine(Sol[0].ToString());
System.Diagnostics.debug.WriteLine(Sol[1].ToString());
System.Diagnostics.debug.WriteLine(Func[0].ToString());
System.Diagnostics.debug.WriteLine(Func[1].ToString());
End If;
End Sub;
See also: