package symjava.examples; import symjava.matrix.ExprMatrix; import symjava.matrix.ExprVector; import symjava.numeric.NumMatrix; import symjava.numeric.NumVector; import symjava.relational.Eq; import symjava.symbolic.Expr; import symjava.symbolic.Symbol; import symjava.symbolic.utils.JIT; import Jama.Matrix; /** * Find maximum or minimum point of eq.lhs() by giving a initial guess * */ public class NewtonOptimization { public static double[] solve(Eq eq, double[] initAndOut, int maxIter, double eps, boolean dislpayOnly) { // if(!Symbol.C0.symEquals(eq.rhs())) { // System.out.println("The right hand side of the equation must be 0."); // return null; // } Expr[] unknowns = eq.getUnknowns(); int n = unknowns.length; //Construct Hessian Matrix ExprVector grad = new ExprVector(n); ExprMatrix hess = new ExprMatrix(n, n); Expr L = eq.lhs(); for(int i=0; i