Calculating System of Non-Linear Equations

This example shows creation of nonlinear equation system:

The system is to be calculated using modified method of simple iterations with the following parameters:

To execute the example, add a link to the Stat system assembly.

Sub UserProc;
Var
    Eqs: ISmNonLinearEquations;
    Funcs: Array[3Of String;
    inits: Array[3Of Double;
    d: Double;
    i, res: Integer;
Begin
    Eqs := New SmNonLinearEquations.Create As ISmNonLinearEquations;
    // Set equations
    funcs[0] := "X1-(1-0.2*X2-0.1*X3)";
    funcs[1] := "X2-(1.2-0.1*X1-0.2*X3)";
    funcs[2] := "X3-(0.8-0.1*X1-0.1*X2)";
    Eqs.Functions := Funcs;
    // Set initial approximations
    inits[0] := -1000;
    inits[1] := 120000;
    inits[2] := 0.8;
    Eqs.InitApproximation := inits;
    // Set coefficient order
    Eqs.CoefficientsOrder := "X1;X2;X3";
    // Set maximum number of iterations, in which solution should be found
    Eqs.MaxIteration := 1000;
    // Set accuracy of solution
    Eqs.Tolerance := 0.00000000001;
    // Set system calculation method
    Eqs.MethodType := NonLinearEquationsType.IterationsMethod;
    // Execute calculation
    res := Eqs.Execute;
    Debug.WriteLine(Eqs.Errors);
    // Output results
    If (res = 0Then
        For i := 0 To (Eqs.Solution.Length - 1Do
            d := Eqs.Solution[i];
            Debug.WriteLine("Value X" + (i + 1).ToString + ": " + d.ToString);
        End For;
        Debug.WriteLine("Values of functions:");
        For i := 0 To Eqs.FunctionValues.Length - 1 Do
            d := Eqs.FunctionValues[i];
            Debug.WriteLine(Eqs.Functions[i] + " = " + d.ToString);
        End For;
    End If;
End Sub UserProc;

After executing the example a nonlinear equation system is created. Next it is to be calculated with the specified parameters. Results are displayed in the console window:

Unit execution started

No errors

Value X1: 0.737172774869517

Value X2: 1.00104712041883

Value X3: 0.626178010471165

Function values:

X1-(1-0.2*X2-0.1*X3) = 3.99458244260131e-13

X2-(1.2-0.1*X1-0.2*X3) = 1.59872115546023e-14

X3-(0.8-0.1*X1-0.1*X2) = 0

Unit execution finished

See also:

Examples