public double[] LinearSystemSolver(string[] variables, string[] functions) { // creating nonlinear system instance - Analytical System NonlinearSystem system = new AnalyticalSystem(variables, functions); double[] x0; SolverOptions options; double[] result; SolutionResult actual; // creating nonlinear solver instance - Newton-Raphson solver. NonlinearSolver solver = new NewtonRaphsonSolver(); x0 = new double[] { 0.2, 0.2 }; // initial guess for variable values options = new SolverOptions() // options for solving nonlinear problem { MaxIterationCount = 100, SolutionPrecision = 1e-5 }; result = null; // solving the system actual = solver.Solve(system, x0, options, ref result); return(result); }
private static void SolverTests() { NonlinearSolver solver; string f1; string f2; string f3; string v1; string v2; string v3; string[] functions; string[] variables; NonlinearSystem system; double[] x0; SolverOptions options; double[] result; double[] expected; SolutionResult actual; f1 = Circle(); f2 = Parabola(); v1 = "x"; v2 = "y"; solver = CreateNewton(); variables = new string[] { v1, v2 }; functions = new string[] { f1, f2 }; system = new AnalyticalSystem(variables, functions); expected = new double[] { 0.7861513778, 0.6180339887 }; x0 = new double[] { 0.2, 0.2 }; options = CreateOptions(); result = null; actual = solver.Solve(system, x0, options, ref result); PrintNlResult(actual, result, expected, options.SolutionPrecision); f1 = Sphere(); f2 = ParaboloidZ(); f3 = ParaboloidX(); v1 = "x"; v2 = "y"; v3 = "z"; solver = CreateNewton(); variables = new string[] { v1, v2, v3 }; functions = new string[] { f1, f2, f3 }; system = new AnalyticalSystem(variables, functions); expected = new double[] { 0.6835507455, 0.3883199288, 0.6180339887 }; x0 = new double[] { 1.0, 1.0, 1.0 }; options = CreateOptions(); result = null; actual = solver.Solve(system, x0, options, ref result); PrintNlResult(actual, result, expected, options.SolutionPrecision); }
public float[] Solve() { NonlinearSystem system = new AnalyticalSystem(_variables, _functions); _options = new SolverOptions() { MaxIterationCount = 100, SolutionPrecision = 1e-5 }; _result = null; // solving the system double[] guess = Array.ConvertAll(_initGuess, x => (double)x); _actual = _solver.Solve(system, guess, _options, ref _result); return(Array.ConvertAll(_result, x => (float)x)); // expected values // printing solution result into console out }