Example 2: Solve a System of Nonlinear Equations with Logging

A system of nonlinear equations is solved with reduced accuracy and logging enabled.
using System;
using Imsl.Math;

public class ZeroSystemEx2 : ZeroSystem.IFunction
{
    public void  F(double[] x, double[] f)
    {
        f[0] = 0.5 * x[0] + x[1] + 0.5 * x[2] - x[5] / x[6];
        f[1] = x[2] + x[3] + 2 * x[4] - 2.0 / x[6];
        f[2] = x[0] + x[1] + x[4] - 1 / x[6];
        f[3] = -28837 * x[0] - 139009 * x[1] - 78213 * x[2] + 18927 *
                x[3] + 8427 * x[4] + 13492 / x[6] - 10690 * x[5] / x[6];
        f[4] = x[0] + x[1] + x[2] + x[3] + x[4] - 1;
        f[5] = 400 * x[0] * x[3] * x[3] * x[3] - 178370.0 * x[2] * x[4];
        f[6] = x[0] * x[2] - 2.6058 * x[1] * x[3];
    }


    public static void  Main(String[] args)
    {        
        ZeroSystem zf = new ZeroSystem(7);
        zf.RelativeError = 0.01;        // reduced accuracy
        double[] guess = { 0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 2.0 };
        zf.SetGuess(guess);

        // enable logging to the console
        zf.Logger = new Imsl.Logger();
        zf.Logger.LogLevel = Imsl.Logger.Level.Finer;

        new PrintMatrix("zeros").Print(zf.Solve(new ZeroSystemEx2()));
    }
}

Output

ZeroSystem: Iteration 1
ZeroSystem: Current solution: 
0.5
ZeroSystem: Convergence if 0.214305934943747 <= 0.0217944947177034
ZeroSystem: Convergence if 881.854579848628 == 0.0
ZeroSystem: Convergence if 0.428611869887493 <= 0.0237140589837329
ZeroSystem: Convergence if 62.2023634352405 == 0.0
ZeroSystem: Iteration 2
ZeroSystem: Current solution: 
0.451941633824387
ZeroSystem: Convergence if 0.214305934943747 <= 0.0237140589837329
ZeroSystem: Convergence if 62.2023634352405 == 0.0
ZeroSystem: Convergence if 0.214305934943747 <= 0.0256689283849008
ZeroSystem: Convergence if 48.6311502628328 == 0.0
ZeroSystem: Iteration 3
ZeroSystem: Current solution: 
0.410355683664779
ZeroSystem: Convergence if 0.107152967471873 <= 0.0256689283849008
ZeroSystem: Convergence if 48.6311502628328 == 0.0
ZeroSystem: Convergence if 0.214305934943747 <= 0.026655240629938
ZeroSystem: Convergence if 24.594369376895 == 0.0
ZeroSystem: Iteration 4
ZeroSystem: Current solution: 
0.389763013577616
ZeroSystem: Convergence if 0.107152967471873 <= 0.026655240629938
ZeroSystem: Convergence if 24.594369376895 == 0.0
ZeroSystem: Convergence if 0.214305934943747 <= 0.0276551655584895
ZeroSystem: Convergence if 11.2333356734159 == 0.0
ZeroSystem: Iteration 5
ZeroSystem: Current solution: 
0.371417874014809
ZeroSystem: Convergence if 0.107152967471873 <= 0.0276551655584895
ZeroSystem: Convergence if 11.2333356734159 == 0.0
ZeroSystem: Convergence if 0.214305934943747 <= 0.0286672864029196
ZeroSystem: Convergence if 4.27372353401102 == 0.0
ZeroSystem: Iteration 6
ZeroSystem: Current solution: 
0.355229191830464
ZeroSystem: Convergence if 0.107152967471873 <= 0.0286672864029196
ZeroSystem: Convergence if 4.27372353401102 == 0.0
ZeroSystem: Convergence if 0.0535764837359367 <= 0.0286672864029196
ZeroSystem: Convergence if 4.27372353401102 == 0.0
ZeroSystem: Iteration 6
ZeroSystem: Current solution: 
0.355229191830464
ZeroSystem: Convergence if 0.107152967471873 <= 0.0291782082184281
ZeroSystem: Convergence if 1.33974481695402 == 0.0
ZeroSystem: Iteration 7
ZeroSystem: Current solution: 
0.347853157507777
ZeroSystem: Convergence if 0.0535764837359367 <= 0.0291782082184281
ZeroSystem: Convergence if 1.33974481695402 == 0.0
ZeroSystem: Convergence if 0.0535764837359367 <= 0.0296908704988974
ZeroSystem: Convergence if 1.21901505512876 == 0.0
ZeroSystem: Iteration 8
ZeroSystem: Current solution: 
0.341044692677201
ZeroSystem: Convergence if 0.0267882418679683 <= 0.0296908704988974
ZeroSystem: Convergence if 1.21901505512876 == 0.0
         zeros
            0           
0  0.341044692677201    
1  0.0080070341885894   
2  0.0406562347121202   
3  0.605298573689315    
4  0.00418754444673453  
5  0.564491500544133    
6  2.83061739420516     


Link to C# source.