// test_46_nl.java compile javac -cp . test_46_nl.java // execute java -cp . test_46_nl // see test_nav2_newton3.java // needs simeq_newton3.java // test Ai,0*x0 + Ai,1*x1 + Ai,2*x2 + Ai,3*x3 + Ai4*x0*x1 + Ai,5*x2*x3 = yi; // 6 variables, thus need values for i=0..5 // public class test_46_nl { int neqn = 4; // for x0, x1, x2, x3 int nlin = 2; // for x0*x1 x2*x3 int ntot = neqn+nlin; double A[][] = new double[neqn][ntot]; // //coef x0 x1 x2 x3 x0*x1 x2*x3 X ,unk Y // | A0,0 A0,1 A0,2 A0,3 A0,4 A0,5 | | X0 | |Y0 | // | A1,0 A1,1 A1,2 A1,3 A1,4 A1,5 | | X1 | |Y1 | // | A2,0 A2,1 A2,2 A2,3 A2,4 A2,5 |*| X2 |=|Y2 | // | A3,0 A3,1 A3,2 A3,3 A3,4 A3,5 | | X3 | |Y3 | // | X0*x1 | // | X2*x3 | // double Y[] = new double[neqn]; double X[] = new double[ntot]; // solution A X = Y int var1[] = { 0, 1, 2, 3, 0, 2}; // products x0*x1 x2*x3 int var2[] = {-1, -1, -1, -1, 1, 3}; int var3[] = {-1, -1, -1, -1, -1, -1}; // all -1 no x0*x1*x2 int maxitr = 25; // maximum iterations of newton method double b = 1.00; // stability factor double eps = 1.0e-6; Boolean debug = true; double x0 = 1.0; // the correct solution double x1 = 2.0; double x2 = 3.0; double x3 = 4.0; double max_err = 0.0; public test_46_nl() // constructor { System.out.println("test_46_nl.java running"); System.out.println("neqn="+neqn+", nlin="+nlin+", ntot="+ntot); System.out.println(" var1, var2, var3 "); for(int i=0; i