private void BuildSolver() { SolutionInput input = BuildInput(); Filter P = input.Filter; Solver newSolver; string errorElem = ""; try { int n = P.Size; errorElem = "D"; double D = double.Parse(input.D); errorElem = "A0"; Complex A0 = ComplexUtils.Parse(input.A_0); errorElem = "K"; double K = double.Parse(input.K); errorElem = "T"; double T = double.Parse(input.T); errorElem = "M"; int M = int.Parse(input.t_count); errorElem = "N"; int N = int.Parse(input.x_count); double chi = Solver.GetChi(K, P[n, n], A0); Dependencies.Set(MathAliases.ConvertName("chi"), chi); errorElem = "u0"; IExpression expr = MainParser.Parse(input.u_0); textBlock_u0.Text = "u0 = " + expr.AsString(); string[] deps = MainParser.GetDependencies(expr); double[] u0 = MainParser.EvalArrayD(expr, Dependencies, deps, "x", 2 * Math.PI, N); errorElem = "solver"; newSolver = new Solver(P, T, N, M); ModelParams param = new ModelParams(A0, K, u0, D); newSolver.SetParams(param); curSolver = newSolver; } catch (Exception ex) { Logger.Write(errorElem + ": " + ex.Message); return; } }
public static Tuple <Complex[], Complex[, ]> UpdateEigen(Filter filter, TextBlock textBlock, ModelParams param) { var eigen = filter.GetEigenValues(param); Logger.Write("eigenvalues:"); Logger.Write(eigen.Item1); Logger.Write("eigenvectors: (columns)"); Logger.Write(eigen.Item2); if (filter.IsDiagonal) { int n_cap = filter.FindDiagCriticalN(param.D, 1, param.K); textBlock.Text = $"K^({n_cap}) = " + filter.FindDiagCritical(param.D, 1, n_cap); textBlock.Text += '\n' + "n^ = " + n_cap; } else { int count = 0; int[] n_cap = new int[eigen.Item1.Length]; bool multi = false; Complex value = 0; for (int n = 0; n < eigen.Item1.Length; n++) { Complex v = eigen.Item1[n]; if (v.Real > -0.001) { if (Math.Abs(value.Imaginary - v.Imaginary) >= 0.001) { multi = true; } n_cap[count] = n; count++; value = v; } } if (count == 0) { textBlock.Text = "No n^"; } else if (multi) { textBlock.Text = "Multi n^"; } else { string text = "λn^ = " + value.ToString("f3") + " (multiplicity=" + count; if (count == 1) { text += ", derivative=" + filter.GetDerivative(n_cap[0], param).ToString("f2") + ")"; } else { text += ")\nderivatives:["; for (int i = 0; i < count; i++) { if (i > 0) { text += ", "; } text += filter.GetDerivative(n_cap[i], param).ToString("f2"); } text += "]"; } textBlock.Text = text; } } return(eigen); }