Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        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]}");
        }