Example 2: Solve a System of Nonlinear Equations with Logging

A system of nonlinear equations is solved with reduced accuracy and logging enabled.

import com.imsl.math.*;
import java.util.logging.*;

public class ZeroSystemEx2 {

    public static void main(String args[]) throws com.imsl.IMSLException {

        ZeroSystem.Function fcn = new ZeroSystem.Function() {

            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];
            }
        };

        ZeroSystem zf = new ZeroSystem(7);
        zf.setRelativeError(1e-2);      // reduced accuracy
        double guess[] = {0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 2.0};
        zf.setGuess(guess);

        Logger logger = zf.getLogger();
        ConsoleHandler ch = new ConsoleHandler();
        ch.setLevel(Level.ALL);         // default ConsoleHandler Level is INFO
        logger.setLevel(Level.FINER);
        logger.addHandler(ch);
        ch.setFormatter(new com.imsl.IMSLFormatter());

        new PrintMatrix("zeros").print(zf.solve(fcn));
    }
}

Output

Iteration 1
Current Solution
        
0  0.5  
1  0    
2  0    
3  0.5  
4  0    
5  0.5  
6  2    


Convergence if 0.2143059349437466 <= 0.02179449471770337
Convergence if 881.8545798486278 == 0.0
Convergence if 0.4286118698874933 <= 0.023714058983732928
Convergence if 62.20236343524046 == 0.0
Iteration 2
    Current Solution
                         
0   0.4519416338243868   
1   0.00047570035964456  
2   0.00811462449691682  
3   0.5413220960737729   
4  -0.00707517903874563  
5   0.5209316770542504   
6   2.20336087353378     


Convergence if 0.21430593494374664 <= 0.023714058983732928
Convergence if 62.20236343524046 == 0.0
Convergence if 0.21430593494374664 <= 0.025668928384900824
Convergence if 48.631150262832776 == 0.0
Iteration 3
    Current Solution
                         
0   0.4103556836647792   
1   0.00345389046504245  
2   0.0205011507011974   
3   0.5643329875514621   
4  -0.00193459468156145  
5   0.5357476651118313   
6   2.4113510334391686   


Convergence if 0.10715296747187332 <= 0.025668928384900824
Convergence if 48.631150262832776 == 0.0
Convergence if 0.21430593494374667 <= 0.026655240629937994
Convergence if 24.594369376894957 == 0.0
Iteration 4
    Current Solution
                        
0  0.38976301357761567  
1  0.00475347250310963  
2  0.02636818944534906  
3  0.5751249696426907   
4  0.00124115547252234  
5  0.5418663859482151   
6  2.5155508333834984   


Convergence if 0.10715296747187333 <= 0.026655240629937994
Convergence if 24.594369376894957 == 0.0
Convergence if 0.2143059349437467 <= 0.027655165558489504
Convergence if 11.23333567341594 == 0.0
Iteration 5
    Current Solution
                        
0  0.37141787401480864  
1  0.00596373459917273  
2  0.03176913111146456  
3  0.5853405218780866   
4  0.00345206419996186  
5  0.5483732628042493   
6  2.620255151899655    


Convergence if 0.10715296747187335 <= 0.027655165558489504
Convergence if 11.23333567341594 == 0.0
Convergence if 0.21430593494374675 <= 0.028667286402919635
Convergence if 4.273723534011024 == 0.0
Iteration 6
    Current Solution
                        
0  0.35522919183046353  
1  0.00699109092408178  
2  0.03660354056250206  
3  0.5951581971633527   
4  0.00460693872783803  
5  0.5557202116250662   
6  2.725343495169716    


Convergence if 0.10715296747187338 <= 0.028667286402919635
Convergence if 4.273723534011024 == 0.0
Convergence if 0.05357648373593669 <= 0.028667286402919635
Convergence if 4.273723534011024 == 0.0
Iteration 6
    Current Solution
                        
0  0.35522919183046353  
1  0.00699109092408178  
2  0.03660354056250206  
3  0.5951581971633527   
4  0.00460693872783803  
5  0.5557202116250662   
6  2.725343495169716    


Convergence if 0.10715296747187338 <= 0.02917820821842807
Convergence if 1.3397448169540218 == 0.0
Iteration 7
    Current Solution
                        
0  0.3478531575077773   
1  0.00752847153174577  
2  0.03866774311942223  
3  0.6004623965959569   
4  0.00437003290309475  
5  0.5601127012361977   
6  2.777917247138637    


Convergence if 0.05357648373593669 <= 0.02917820821842807
Convergence if 1.3397448169540218 == 0.0
Convergence if 0.05357648373593669 <= 0.02969087049889735
Convergence if 1.2190150551287604 == 0.0
Iteration 8
    Current Solution
                        
0  0.3410446926772013   
1  0.0080070341885894   
2  0.04065623471212016  
3  0.6052985736893154   
4  0.00418754444673453  
5  0.564491500544133    
6  2.830617394205158    


Convergence if 0.026788241867968344 <= 0.02969087049889735
Convergence if 1.2190150551287604 == 0.0
  zeros
     0    
0  0.341  
1  0.008  
2  0.041  
3  0.605  
4  0.004  
5  0.564  
6  2.831  

Link to Java source.