package com.imsl.test.example.math; import com.imsl.math.*; import java.util.logging.*; /** *
* ZeroSystem Example 2: Solves a system of nonlinear equations with logging * enabled.
* * * The following system is solved with a higher relative error tolerance and * logging enabled. * * $$ * \begin{align} * y_0 &= 0.5 * x_0 + x_1 + 0.5 * x_2 - x_5 / x_6 \\ * y_1 &= x_2 + x_3 + 2 * x_4 - 2.0 / x_6 \\ * y_2 &= x_0 + x_1 + x_4 - 1 / x_6 \\ * y_3 &= -28837 * x_0 - 139009 * x_1 - 78213 * x_2 + 18927 x_3 + 8427 * x_4 + 13492 / x_6 - 10690 * x_5 / x_6 \\ * y_4 &= x_0 + x_1 + x_2 + x_3 + x_4 - 1 \\ * y_5 &= 400 * x_0 * x_3 * x_3 * x_3 - 178370.0 * x_2 * x_4 \\ * y_6 &= x_0 * x_2 - 2.6058 * x_1 * x_3 * \end{align} * $$ * * @see Code * @see Output */ public class ZeroSystemEx2 { public static void main(String args[]) throws com.imsl.IMSLException { ZeroSystem.Function fcn = new ZeroSystem.Function() { @Override 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)); } }