Example 1: Solve a System of Nonlinear Equations

A system of nonlinear equations is solved.

import com.imsl.math.*;

public class ZeroSystemEx1 {

    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] = x[0] + Math.exp(x[0] - 1.0) +
                        (x[1] + x[2]) * (x[1] + x[2]) - 27.0;
                f[1] = Math.exp(x[1] - 2.0) / x[0] + x[2] * x[2] - 10.0;
                f[2] = x[2] + Math.sin(x[1] - 2.0) + x[1] * x[1] - 7.0;
            }
        };

        ZeroSystem zf = new ZeroSystem(3);
        double guess[] = {4, 4, 4};
        zf.setGuess(guess);
        new PrintMatrix("zeros").print(zf.solve(fcn));
    }
}

Output

zeros
   0  
0  1  
1  2  
2  3  

Link to Java source.