public MainPage() { InitializeComponent(); var gear = Ode.GearBDF( 0, // Initial time point new Vector(2.0, 0.0), // Initial X vector VanDerPol, new Options { MinStep = 1e-6, MaxStep = 1e-1 }); // Right part var rk = Ode.RK547M( 0, // Initial time point new Vector(2.0, 0.0), // Initial X vector VanDerPol, new Options { MinStep = 1e-6, MaxStep = 1e-1 }); // Right part // Append time step as extra vector component and solve from t = 0 to 20 and output points with step 0.01 var edg = gear.AppendStep().SolveFromTo(0.0, 20.0).ToArray(); var edrk = rk.AppendStep().SolveFromTo(0.0, 20.0).ToArray(); // Draw numeric solution x1 = (LineGraph)plotter.FindName("x1"); x1.PlotY(edrk.Select(sp => sp.X[0])); x2 = (LineGraph)plotter.FindName("x2"); x2.PlotY(edrk.Select(sp => sp.X[1])); x1_1 = (LineGraph)plotter.FindName("x1_1"); x1_1.PlotY(edg.Select(sp => sp.X[0])); x2_1 = (LineGraph)plotter.FindName("x2_1"); x2_1.PlotY(edg.Select(sp => sp.X[1])); }
public MainPage() { InitializeComponent(); //An example of Gear method use var rk1 = Ode.GearBDF( 0, // Initial time point new Microsoft.Research.Oslo.Vector(1000.0), // Initial X vector (t, x) => { return(new Vector(-0.01 * x[0])); }, // Right part new Options { MaxStep = 5.0d, NumberOfIterations = 4 }); var eds1 = rk1.AppendStep().SolveFromToStep(0, 2000, 0.1).ToArray(); var x11 = eds1.Select(p => new Point(p.T, p.X[0])).ToArray(); linegraph1.Plot(x11.Select(x => x.X).ToArray(), x11.Select(x => x.Y).ToArray()); //An example of RK method use var rk2 = Ode.RK547M( 0, // Initial time point new Microsoft.Research.Oslo.Vector(1000.0), // Initial X vector (t, x) => { return(new Vector(-0.01 * x[0])); }); // Right part var eds2 = rk2.AppendStep().SolveFromToStep(0, 2000, 0.1).ToArray(); var x12 = eds2.Select(p => new Point(p.T, p.X[0])).ToArray(); linegraph2.Plot(x12.Select(x => x.X).ToArray(), x12.Select(x => 1000 * Math.Exp(-0.01d * x.X)).ToArray()); var err = x11.Max(x => Math.Abs(x.Y - 1000 * Math.Exp(-0.01d * x.X))); }
public IReadOnlyList <WorkingProbability> GetProbability(double from, double to, double step) { var coefficients = BuildWeightMatrix(); // The initial vector describes the situation when the first state // holds true - the state where all modules are working var initial = new Vector(Enumerable.Repeat(0.0, AllPossibleStates.Count).ToArray()) { [0] = 1.0 }; var solution = Ode.RK547M( 0, initial, (_, vector) => GetNextStateProbabilityDistribution(vector, coefficients)); var workingIndices = AllPossibleStates .Select((state, index) => new { index, state.IsWorking }) .Where(state => state.IsWorking) .Select(state => state.index) .ToArray(); var points = solution.SolveFromToStep(from, to, step).ToArray(); return(points.Select(point => new WorkingProbability { Time = point.T, AggregatedProbability = point.X.ToArray().Where((_, index) => workingIndices.Contains(index)).Sum() }).ToList()); }
public SolPoint[] Count2() { var sol = Ode.RK547M(0, new Vector(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), (t, x) => new Vector( -(parameters.LambdaAZ1 + parameters.LambdaPZ1 + parameters.LambdaAZ3 + parameters.LambdaAZ2 + parameters.LambdaAZ4 + parameters.LambdaAZ5) * x[0] + parameters.MuAZ1 * x[1] + parameters.MuPZ1 * x[2] + parameters.MuAZ2 * x[3] + parameters.MuAZ3 * x[4] + parameters.MuPZ3 * x[5] + parameters.MuAZ4 * x[6] + parameters.MuAZ5 * x[6], -(parameters.LambdaPZ1 + parameters.LambdaAZ2 + parameters.MuAZ1) * x[1] + parameters.MuPZ1 * x[8] + parameters.MuAZ1 * x[9] + parameters.LambdaAZ5 * x[6], -(parameters.LambdaAZ1 + parameters.LambdaAZ2 + parameters.MuPZ1) * x[2] + parameters.MuAZ1 * x[7] + parameters.MuAZ2 * x[9] + parameters.LambdaPZ1 * x[0], -parameters.MuAZ2 * x[3] + parameters.LambdaAZ2 * x[0], -(parameters.LambdaPZ3 + parameters.LambdaAZ3 + parameters.MuAZ3) * x[4] + parameters.MuPZ3 * x[11] + parameters.MuAZ4 * x[17] + parameters.LambdaAZ3 * x[0], -(parameters.LambdaAZ3 + parameters.LambdaAZ4 + parameters.MuPZ3) * x[5] + parameters.MuAZ3 * x[11] + parameters.MuAZ4 * x[18] + parameters.LambdaPZ3 * x[0], -parameters.MuAZ4 * x[6] + parameters.LambdaAZ4 * x[0], -parameters.MuAZ5 * x[7] + parameters.LambdaAZ5 * x[0], -(parameters.LambdaAZ3 + parameters.LambdaPZ3 + parameters.MuPZ1 + parameters.MuAZ1) * x[7] + parameters.MuAZ3 * x[12] + parameters.MuPZ3 * x[13] + parameters.LambdaPZ1 * x[1] + parameters.LambdaAZ1 * x[2], -parameters.MuAZ2 * x[9] + parameters.LambdaAZ2 * x[1], -parameters.MuAZ2 * x[10] + parameters.LambdaAZ2 * x[2], -(parameters.LambdaAZ1 + parameters.LambdaPZ1 + parameters.MuPZ3 + parameters.MuAZ3) * x[11] + parameters.MuAZ1 * x[14] + parameters.MuPZ1 * x[15] + parameters.LambdaPZ3 * x[4] + parameters.LambdaAZ3 * x[5], -(parameters.LambdaPZ3 + parameters.MuAZ3) * x[12] + parameters.MuPZ3 * x[16] + parameters.LambdaAZ3 * x[8], -(parameters.LambdaAZ3 + parameters.MuPZ3) * x[13] + parameters.MuAZ3 * x[16] + parameters.LambdaPZ3 * x[8], -(parameters.LambdaPZ1 + parameters.MuAZ1) * x[14] + parameters.MuPZ1 * x[16] + parameters.LambdaAZ1 * x[14], -(parameters.LambdaAZ1 + parameters.MuPZ1) * x[15] + parameters.MuAZ1 * x[16] + parameters.LambdaPZ1 * x[11], -(parameters.MuAZ3 + parameters.MuPZ3 + parameters.MuPZ1 + parameters.MuAZ1) * x[16] + parameters.LambdaAZ3 * x[13] + parameters.LambdaPZ3 * x[12] + parameters.LambdaPZ1 * x[14] + parameters.LambdaAZ1 * x[15], -parameters.MuAZ4 * x[17] + parameters.LambdaAZ4 * x[4], -parameters.MuAZ4 * x[18] + parameters.LambdaAZ4 * x[5] )); return(sol.SolveFromToStep(0, parameters.MaxTime, parameters.Step).ToArray()); }
public SolPoint[] calcSIR() { var sol = Ode.RK547M( 0, new Vector(SuseptipleFaction, InfectedFaction), (t, x) => new Vector( (1 - p) * f - r0 * x[0] * x[1] - f * x[0], r0 * x[0] * x[1] - x[1])); var points = sol.SolveFromToStep(0, TimeLimit, Step).ToArray(); return(points); }
public void ExponentSolveToRKTest() { foreach (var sp in Ode.RK547M(0, 1, (t, x) => - x, new Options { RelativeTolerance = 1e-3 }).SolveTo(1000)) { Assert.IsTrue(Math.Abs(sp.X[0] - Math.Exp(-sp.T)) < 1e-2); } }
public void ExponentSolveToArrayTest() { var arr = Ode.RK547M(0, 1, (t, x) => - x, new Options { RelativeTolerance = 1e-3 }).SolveTo(1000).ToArray(); foreach (var sp in arr) { Assert.IsTrue(Math.Abs(sp.X[0] - Math.Exp(-sp.T)) < 1e-2); // AbsTol instead of 1e-4 } }
public IEnumerable <SolPoint> Solve() { var sol = Ode.RK547M( 0, new Vector(Ag, D, Ab), (t, x) => new Vector( b * x[0] - y * x[2] * x[0], a * x[0] - mc * x[1], p * x[1] - n * x[0] * x[2] - mf * x[2] ) ); return(sol.SolveFromToStep(0, 100, 1)); }
public static SolPoint[] RK547M(int setNumber) { SolPoint[] wynik; try { wynik = Ode.RK547M(initialTime[setNumber], initialAdopters[setNumber], (t, x) => (p[setNumber] * (finalAdopters[setNumber] - x)) + ((q[setNumber] * x / (double)finalAdopters[setNumber]) * (finalAdopters[setNumber] - x)) - (u[setNumber] * x)).SolveTo(finalTime[setNumber]).ToArray(); } catch (Exception e) { Console.WriteLine("Napotkano błąd! Treść: " + e.ToString()); Console.ReadKey(); return(null); } return(wynik); }
public MainPage() { InitializeComponent(); //Try to solve ODE dx / dt = Sin(t), x(0) = 0 //An example of RK547M method use var rk1 = Ode.RK547M(0, 20, new Microsoft.Research.Oslo.Vector(0), (t, x) => { return(new Vector(Math.Cos(t))); }// Right part ); //An example of Gear method use var rk2 = Ode.GearBDF(0, 20, new Microsoft.Research.Oslo.Vector(0), (t, x) => { return(new Vector(Math.Cos(t))); }// Right part ); SinT.Plot(rk2.Select(x => x.T).ToArray(), rk2.Select(x => Math.Sin(x.T)).ToArray()); SinRK.Plot(rk1.Select(x => x.T).ToArray(), rk1.Select(x => x.X[0]).ToArray()); SinGear.Plot(rk2.Select(x => x.T).ToArray(), rk2.Select(x => x.X[0]).ToArray()); }
public MainPage() { InitializeComponent(); var rk = Ode.RK547M( 0, // Initial time point new Vector(1.01, 3), // Initial X vector Brusselator); // Right part // Append time step as extra vector component and solve from t = 0 to 20 and output points with step 0.01 var ed = rk.AppendStep().SolveFromToStep(0, 20, 0.01).ToArray(); // Draw numeric solution x1 = (LineGraph)plotter.FindName("x1"); x1.PlotY(ed.Select(sp => sp.X[0])); x2 = (LineGraph)plotter.FindName("x2"); x2.PlotY(ed.Select(sp => sp.X[1])); }
public void OSLO(double step) { double T = 2 * Math.PI / Math.Sqrt(alpha * gamma); T *= 15; var sol = Ode.RK547M(0, new Vector(x0, y0), (t, x) => new Vector( (alpha - beta * x[1]) * x[0], (-gamma + delta * x[0]) * x[1] ) ); var points = sol.SolveFromToStep(0, T, step).ToArray(); solution = new List <double[]>(); double[] p0 = new double[2] { points[0].X[0], points[0].X[1] }; double[] p1 = new double[2] { points[1].X[0], points[1].X[1] }; double d0 = Utils.Distance(p0, p1); solution.Add(new double[] { points[0].X[0], points[0].X[1], points[0].T }); solution.Add(new double[] { points[1].X[0], points[1].X[1], points[1].T }); for (int i = 2; i < points.Count(); i++) { double d = Utils.Distance(p0, new double[2] { points[i].X[0], points[i].X[1] }); if (d > d0) { solution.Add(new double[] { points[i].X[0], points[i].X[1], points[i].T }); } else { solution.Add(new double[] { points[0].X[0], points[0].X[1], points[0].T }); break; } } }
/** \brief Calculates temperature of the water: the average kinetic energy of the particles within the water (degreeC) * \param T_C temperature of the heating coil: the average kinetic energy of the particles within the coil (degreeC) * \param t_final final time: the amount of time elapsed from the beginning of the simulation to its conclusion (s) * \param T_init initial temperature: the temperature at the beginning of the simulation (degreeC) * \param A_tol absolute tolerance * \param R_tol relative tolerance * \param t_step time step for simulation: the finite discretization of time used in the numerical method for solving the computational model (s) * \param tau_W ODE parameter for water related to decay time: derived parameter based on rate of change of temperature of water (s) * \return temperature of the water: the average kinetic energy of the particles within the water (degreeC) */ public static List <double> func_T_W(double T_C, double t_final, double T_init, double A_tol, double R_tol, double t_step, double tau_W) { List <double> T_W; Func <double, Vector, Vector> f = (t, T_W_vec) => { return(new Vector(1.0 / tau_W * (T_C - T_W_vec[0]))); }; Options opts = new Options(); opts.AbsoluteTolerance = A_tol; opts.RelativeTolerance = R_tol; Vector initv = new Vector(T_init); IEnumerable <SolPoint> sol = Ode.RK547M(0.0, initv, f, opts); IEnumerable <SolPoint> points = sol.SolveFromToStep(0.0, t_final, t_step); T_W = new List <double> { }; foreach (SolPoint sp in points) { T_W.Add(sp.X[0]); } return(T_W); }