void Solve(int partSumOrder, int iterCount, int nodesCount) { var chunksCount = (int)nupChunksCount.Value; var(segment, y0, f, yExact) = Example3(); var nodes = Range(0, nodesCount).Select(j => segment.Start + segment.Length * j / (nodesCount - 1)).ToArray(); if (yExact != null) { //nodes = Range(0, nodesCount).Select(j => 1.0*j / nodesCount).ToArray(); exactSolutionPlot.DiscreteFunctions = new[] { new DiscreteFunction2D(x => yExact(x), nodes) }; exactSolutionPlot.Refresh(); } //nodes = Range(0, nodesCount).Select(j => segment.Start + segment.Length * j / nodesCount).ToArray(); var cosSystem = new CosSystem(); var sobCosSystem = new SobolevCosSystem(); var solverIter = new CosSpectralSolverIter(1000); var problem = new CauchyProblem(f, y0, segment); var df = solverIter.Solve(problem, chunksCount, partSumOrder, iterCount, nodesCount); //df.X = df.X.Select(x => x).ToArray(); numSolutionPlotIter.Colors = Colors; numSolutionPlotIter.DiscreteFunctions = df.Select(d => d[0]).ToArray(); numSolutionPlotIter.Refresh(); //numSolutionPlotIter2.DiscreteFunctions = df[1]; //numSolutionPlotIter2.Refresh(); }
private static ISpectralOdeOperator <double[][]> CreateOperator(int quadratureNodesCount) { // Used to calculate coeffs that are represented as integrals var quadratureNodes = new Segment(0, 1).GetUniformPartition(quadratureNodesCount); var cosSystem = new CosSystem(); var sobCosSystem = new SobolevCosSystem(); var op = new CosSpectralOdeOperator(Natural.NumbersWithZero.Select(k => cosSystem.Get(k)), Natural.NumbersWithZero.Select(k => sobCosSystem.Get(k)), quadratureNodes); return(op); }
public void CosSytemOrthonormality() { var cosSystem = new CosSystem(); for (int i = 0; i < 100; i++) { var i1 = i; var v = Integrals.Trapezoid(x => cosSystem.Get(i1)(x) * cosSystem.Get(i1)(x), 0, 1, 10000); Assert.AreEqual(1, v, 0.0000001); } var val = Integrals.Trapezoid(x => cosSystem.Get(0)(x) * cosSystem.Get(5)(x), 0, 1, 10000); Assert.AreEqual(0, val, 0.0000001); val = Integrals.Trapezoid(x => cosSystem.Get(4)(x) * cosSystem.Get(5)(x), 0, 1, 10000); Assert.AreEqual(0, val, 0.0000001); }
void SolveSystem(int partSumOrder, int iterCount, int nodesCount) { var chunksCount = (int)nupChunksCount.Value; var(segment, initVals, f, h, yExact) = ExampleSystem6(); var nodes = Range(0, nodesCount).Select(j => segment.Start + segment.Length * j / (nodesCount - 1)).ToArray(); if (yExact != null) { exactSolutionPlot.DiscreteFunctions = yExact.Select(y => new DiscreteFunction2D(y, nodes)).ToArray(); exactSolutionPlot.Refresh(); } var cosSystem = new CosSystem(); var sobCosSystem = new SobolevCosSystem(); var solverIter = new CosSpectralSolverIter(1000); var problem = new CauchyProblem(f, initVals, segment); var solution = solverIter.Solve(problem, chunksCount, partSumOrder, iterCount, nodesCount); var dfs = new List <DiscreteFunction2D>(); foreach (var s in solution) { dfs.AddRange(s); } numSolutionPlotIter.Colors = Colors; numSolutionPlotIter.DiscreteFunctions = dfs.ToArray(); numSolutionPlotIter.Refresh(); //var deltas = solution.Zip(yExact, (df, y) => Abs(df.Y.Last() - y(df.X.Last()))).ToArray(); //var deltas = solution.Zip(yExact, (df, y) => // { // var eDf = new DiscreteFunction2D(y, df.X); // return Sqrt((df - eDf).Y.Average(v => v * v)); // } // ).ToArray(); //Trace.WriteLine($"iter={iterCount}; N={partSumOrder}; dy1={deltas[0]};dy2={deltas[1]}"); }