public string Solve() { Compiler compiler = new Compiler(); if (frequencies.Count == 0) { frequencies.Add(0.0); } for (int i = 0; i < elements.Count; i++) { (elements[i] as Element).SetIndex(i); } string equations = GenerateEquations(); List <IScopeElement> scopeElements = new List <IScopeElement>(); foreach (var element in elements) { if (element is IScopeElement) { scopeElements.Add(element as IScopeElement); } } SteadyStateSolution solution = new SteadyStateSolution(frequencies.Count, scopeElements.Count); int frequencyIndex = 0; foreach (var frequency in frequencies) { string system = equations; system += "//Parameters" + Environment.NewLine; system += GenerateParameters(frequency); //parse equations NonlinearEquationDescription compiledEquation = compiler.CompileEquations(system); NonlinearSystemSymbolicAnalytic nonlinearSystem = new NonlinearSystemSymbolicAnalytic(compiledEquation); //solve Vector <double> values = solver.Solve(nonlinearSystem, Vector <double> .Build.DenseOfArray(compiledEquation.InitialValues)); NonlinearSystemSolution systemSolution = compiledEquation.GetSolution(values); //save results int index = 0; foreach (var scope in scopeElements) { solution.Set(scope.GetReading(systemSolution), index, frequencyIndex); index++; } frequencyIndex++; } return(solution.ToString(scopeElements, frequencies.ToArray())); }
//<summary><summary> Vector <double> ISteadyStateSolver.Solve(NonlinearSystemSymbolicAnalytic system, Vector <double> x0) { Vector <double> x = x0; Vector <double> F = system.F(x); for (int i = 0; i < iterations; i++) { Matrix <double> J = system.DF(x); Vector <double> dx = J.Solve(F.Multiply(-alpha)); Vector <double> x_new = x + dx; Vector <double> F_new = system.F(x_new); x = x_new; if (F_new.L2Norm() < fAbsTol) { return(x); } F = F_new; } throw new Exception("Решение не сошлось"); }