private void Iterate() { for (var i = 0; i < _currentSolution.Length; i++) { _prevSolution[i] = _currentSolution[i]; } var jacobi = CountJacobi(); var templeB = new double[_funcSystem.Length]; for (var i = 0; i < _funcSystem.Length; i++) { templeB[i] = -_funcSystem[i](_currentSolution); } var lupHelper = new Lup(jacobi); _currentSolution = lupHelper.LesSol(templeB); for (var i = 0; i < _funcSystem.Length; i++) { _currentSolution[i] += _prevSolution[i]; } CountOfIterationInLastSolution++; }
public double[] GetSolutionWithAccuracySuperModified(double[] startVector, double accuracy, int iterationTrigger) { CountOfIterationInLastSolution = 0; for (var i = 0; i < startVector.Length; i++) { _currentSolution[i] = startVector[i]; } Iterate(); while (CountCurrentAccuracy() > accuracy) { if (iterationTrigger > CountOfIterationInLastSolution) { Iterate(); } else { var jacobi = CountJacobi(); var lupHelper = new Lup(jacobi); while (CountCurrentAccuracy() > accuracy) { IterateModified(lupHelper); } } } return(_currentSolution); }
public double[] GetIqf(double start, double end, double[] nodes) { var moments = new double[nodes.Length]; for (var i = 0; i < nodes.Length; i++) { moments[i] = CalcWeightFunctionMomentAnalytics(start, end, i); } var aMatrix = new double[nodes.Length][]; for (var i = 0; i < nodes.Length; i++) { aMatrix[i] = new double[nodes.Length]; for (var j = 0; j < nodes.Length; j++) { aMatrix[i][j] = Math.Pow(nodes[j], i); } } var lupHelper = new Lup(aMatrix); var result = lupHelper.LesSol(moments); return(result); }
private double[] GetGqf(double start, double end, out double[] nodes) { var moments = new double[CountOfNodes * 2]; var bMoments = new double[CountOfNodes]; var matrixWithMoments = new double[CountOfNodes][]; for (var i = 0; i < CountOfNodes * 2; i++) { moments[i] = CalcWeightFunctionMomentAnalytics(start, end, i); } for (var i = 0; i < CountOfNodes; i++) { matrixWithMoments[i] = new double[CountOfNodes]; for (var j = 0; j < CountOfNodes; j++) { matrixWithMoments[i][j] = moments[i + j]; } bMoments[i] = -moments[i + CountOfNodes]; } var lupHelper = new Lup(matrixWithMoments); var polynomialCoeff = lupHelper.LesSol(bMoments); nodes = GetPolRoot(polynomialCoeff); var result = _iqfHelper.GetIqf(start, end, nodes); return(result); }
public double[] GetSolutionWithAccuracyModified(double[] startVector, double accuracy) { CountOfIterationInLastSolution = 0; for (var i = 0; i < startVector.Length; i++) { _currentSolution[i] = startVector[i]; } var jacobi = CountJacobi(); var lupHelper = new Lup(jacobi); do { IterateModified(lupHelper); } while (CountCurrentAccuracy() > accuracy); return(_currentSolution); }
private void IterateModified(Lup lupHelper) { for (var i = 0; i < _currentSolution.Length; i++) { _prevSolution[i] = _currentSolution[i]; } var templeB = new double[_funcSystem.Length]; for (var i = 0; i < _funcSystem.Length; i++) { templeB[i] = -_funcSystem[i](_prevSolution); } _currentSolution = lupHelper.LesSol(templeB); for (var i = 0; i < _funcSystem.Length; i++) { _currentSolution[i] += _prevSolution[i]; } CountOfIterationInLastSolution++; }
public double[] GetSolutionWithAccuracyHybrid(double[] startVector, double accuracy, int iterationTrigger) { for (var i = 0; i < _funcSystem.Length; i++) { _currentSolution[i] = startVector[i]; } var jacobi = CountJacobi(); var lupHelper = new Lup(jacobi); do { if (CountOfIterationInLastSolution % iterationTrigger == 0 && CountOfIterationInLastSolution != 0) { jacobi = CountJacobi(); lupHelper = new Lup(jacobi); } IterateModified(lupHelper); } while (CountCurrentAccuracy() > accuracy); return(_currentSolution); }
private double CalcAccuracyRichardson(double[] integralsValues, int[] steps, double start, double end) { if (integralsValues.Length < 3) { return(Math.Abs(integralsValues.Last() - integralsValues.First())); } var aitkinConstant = CalcAitkinConstant(integralsValues, steps); var lesRichardson = new double[integralsValues.Length][]; for (var i = 0; i < integralsValues.Length; i++) { lesRichardson[i] = new double[integralsValues.Length]; for (var j = 0; j < integralsValues.Length - 1; j++) { lesRichardson[i][j] = Math.Pow((end - start) / steps[i], aitkinConstant + j); } lesRichardson[i][integralsValues.Length - 1] = -1; } var negativeIntegralValues = new double[integralsValues.Length]; for (var i = 0; i < integralsValues.Length; i++) { negativeIntegralValues[i] = -integralsValues[i]; } var lupHelper = new Lup(lesRichardson); var expectedError = lupHelper.LesSol(negativeIntegralValues); return(integralsValues.Select((integralValue, i) => Math.Abs(integralValue - expectedError[integralsValues.Length - 1])).Min()); }