CoefficientsOrder: String;
CoefficientsOrder: string;
The CoefficientsOrder property determines the variables used in the function.
The function is determined by the ISmDerivative.Expression property.
To execute the example, add a link to the Stat system assembly.
Sub UserProc;
Var
AnDeriv: ISmDerivative;
ArgVals: Array[0..3] Of Double;
i, res, size: Integer;
Begin
AnDeriv := New SmDerivative.Create;
// Set expression for differentiation
AnDeriv.Expression := "A1 + A2 * A2 + A3 * A3 * A2";
// Specify variables order
AnDeriv.CoefficientsOrder := "A1;A2;A3;A4";
// Specify differentiation variables
AnDeriv.DiffVariables := "A2;A1";
// Set values for variables
ArgVals[0] := 1.5;
ArgVals[1] := 2.0;
ArgVals[2] := 2.5;
ArgVals[3] := Double.Nan;
AnDeriv.VariablesValues := ArgVals;
// Indicate that analytical derivatives are calculated
AnDEriv.UseAnalyticCalc := True;
res := AnDeriv.Execute;
// Output calculation results
Debug.WriteLine("Execution status: " + res.ToString);
Debug.WriteLine(AnDeriv.Errors);
For i := 0 To AnDeriv.Warnings.Length - 1 Do
Debug.WriteLine(AnDeriv.Warnings[i]);
End For;
If res = 0 Then
Debug.WriteLine("== Analytical derivatives ==");
size := AnDeriv.DerivativeExpressions.Length;
For i := 0 To size - 1 Do
Debug.Write(" - derivative expression: ");
Debug.WriteLine(AnDeriv.DerivativeExpressions[i]);
Debug.Write(" - value of derivative: ");
Debug.WriteLine(AnDeriv.DerivativeValues[i]);
Debug.WriteLine("");
End For;
Debug.WriteLine("Function value: " + Anderiv.FunctionValue.ToString);
End If;
Debug.WriteLine("");
// Indicate that approximate values of partial derivatives are calculated
AnDEriv.UseAnalyticCalc := False;
// Specify increment of the argument
AnDEriv.Increment := 0.00000003;
res := AnDeriv.Execute;
// Output calculation results
Debug.WriteLine("Execution status: " + res.ToString);
Debug.WriteLine(AnDeriv.Errors);
For i := 0 To AnDeriv.Warnings.Length - 1 Do
Debug.WriteLine(AnDeriv.Warnings[i]);
End For;
If res = 0 Then
Debug.WriteLine("== Approximate values of partial derivatives ==");
size := AnDeriv.DerivativeValues.Length;
For i := 0 To size - 1 Do
Debug.WriteLine(AnDeriv.DerivativeValues[i]);
End For;
Debug.WriteLine("Function value: " + Anderiv.FunctionValue.ToString);
End If;
End Sub UserProc;
After executing the example the console window displays the results of function calculation using analytical derivatives and approximate values of partial derivatives.
Imports Prognoz.Platform.Interop.Stat;
…
Public Shared Sub Main(Params: StartParams);
Var
AnDeriv: ISmDerivative;
ArgVals: Array[0..3] Of Double;
i, res, size: Integer;
Begin
AnDeriv := New SmDerivative.Create();
// Set expression for differentiation
AnDeriv.Expression := "A1 + A2 * A2 + A3 * A3 * A2";
// Specify variables order
AnDeriv.CoefficientsOrder := "A1;A2;A3;A4";
// Specify differentiation variables
AnDeriv.DiffVariables := "A2;A1";
// Set values for variables
ArgVals[0] := 1.5;
ArgVals[1] := 2.0;
ArgVals[2] := 2.5;
ArgVals[3] := Double.Nan;
AnDeriv.VariablesValues := ArgVals;
// Indicate that analytical derivatives are calculated
AnDEriv.UseAnalyticCalc := True;
res := AnDeriv.Execute();
// Output calculation results
System.Diagnostics.Debug.WriteLine("Execution status: " + res.ToString());
System.Diagnostics.Debug.WriteLine(AnDeriv.Errors);
For i := 0 To AnDeriv.Warnings.Length - 1 Do
System.Diagnostics.Debug.WriteLine(AnDeriv.Warnings.GetValue(i));
End For;
If res = 0 Then
System.Diagnostics.Debug.WriteLine("== Analytical derivatives ==");
size := AnDeriv.DerivativeExpressions.Length;
For i := 0 To size - 1 Do
System.Diagnostics.Debug.Write(" - derivative expression: ");
System.Diagnostics.Debug.WriteLine(AnDeriv.DerivativeExpressions.GetValue(i));
System.Diagnostics.Debug.Write(" - value of derivative: ");
System.Diagnostics.Debug.WriteLine(AnDeriv.DerivativeValues.GetValue(i));
System.Diagnostics.Debug.WriteLine("");
End For;
System.Diagnostics.Debug.WriteLine("Function value: " + Anderiv.FunctionValue.ToString());
End If;
System.Diagnostics.Debug.WriteLine("");
// Indicate that approximate values of partial derivatives are calculated
AnDEriv.UseAnalyticCalc := False;
// Specify increment of the argument
AnDEriv.Increment := 0.00000003;
res := AnDeriv.Execute();
// Output calculation results
System.Diagnostics.Debug.WriteLine("Execution status: " + res.ToString());
System.Diagnostics.Debug.WriteLine(AnDeriv.Errors);
For i := 0 To AnDeriv.Warnings.Length - 1 Do
System.Diagnostics.Debug.WriteLine(AnDeriv.Warnings.GetValue(i));
End For;
If res = 0 Then
System.Diagnostics.Debug.WriteLine("== Approximate values of partial derivatives ==");
size := AnDeriv.DerivativeValues.Length;
For i := 0 To size - 1 Do
System.Diagnostics.Debug.WriteLine(AnDeriv.DerivativeValues.GetValue(i));
End For;
System.Diagnostics.Debug.WriteLine("Function value: " + Anderiv.FunctionValue.ToString());
End If;
End Sub;
After executing the example the console window displays the results of function calculation using analytical derivatives and approximate values of partial derivatives.
See also: