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:

Sub Main;

Var

Eqs: ISmNonLinearEquations;

Funcs: Array[3] Of String;

inits: Array[3] Of Double;

d: Double;

i, res: Integer;

Begin

Eqs := New SmNonLinearEquations.Create As ISmNonLinearEquations;

// Specify 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;

// Specify initial approximations

inits[0] := -1000;

inits[1] := 120000;

inits[2] := 0.8;

Eqs.InitApproximation := inits;

// Specify coefficients order

Eqs.CoefficientsOrder := "X1;X2;X3";

// Specify maximum iterations to find a solution

Eqs.MaxIteration := 1000;

// Set solution accuracy

Eqs.Tolerance := 0.00000000001;

// Specify method for system calculation

Eqs.MethodType := NonLinearEquationsType.IterationsMethod;

// Execute calculation

res := Eqs.Execute;

Debug.WriteLine(Eqs.Errors);

// Display results

If (res = 0) Then

For i := 0 To (Eqs.Solution.Length - 1) Do

d := Eqs.Solution[i];

Debug.WriteLine("Value (i + 1).ToString + ": " + d.ToString);

End For;

Debug.WriteLine("Function values

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 Main;

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:

Module execution started

No errors

Value X1: 0.73717277486942689

Value X2: 1.0010471204188958

Value X3: 0.62617801047116783

Function values:

X1-(1-0.2*X2-0.1*X3) = 3.2285285556099552E-013

X2-(1.2-0.1*X1-0.2*X3) = 7.2164496600635175E-014

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

Module execution finished

See also:

Examples