public void OdeExponential() { // Exponential // y = y_0 e^{x - x_0} Func <double, double, double> f = (double x, double y) => y; double y1 = FunctionMath.SolveOde(f, 0.0, 1.0, 2.0); Assert.IsTrue(TestUtilities.IsNearlyEqual(y1, MoreMath.Sqr(Math.E))); }
public void OdeExample() { Func <double, double, double> rhs = (double t, double u) => (1.0 - 2.0 * t) * u; Func <double, double, double> solution = (double u0, double t) => u0 *Math.Exp(t - t *t); foreach (double t in new double[] { 0.5, 0.75, 1.50, 2.25, 3.25 }) { double y1 = FunctionMath.SolveOde(rhs, 0.0, 1.0, t); Assert.IsTrue(TestUtilities.IsNearlyEqual(y1, solution(1.0, t))); } }
public void OdeNonlinear() { // y = \frac{y_0}{1 - y_0 (x - x_0)} Func <double, double, double> f = (double x, double y) => MoreMath.Sqr(y); EvaluationSettings settings = new EvaluationSettings() { RelativePrecision = 1.0E-8, EvaluationBudget = 1000 }; double y1 = FunctionMath.SolveOde(f, 0.0, 1.0, 0.99, settings); Console.WriteLine(y1); Assert.IsTrue(TestUtilities.IsNearlyEqual(y1, 1.0 / (1.0 - 1.0 * (0.99 - 0.0)), settings)); }
public void OdeLogistic() { // y = \frac{y_0}{y_0 + (1 - y_0) e^{-(x - x_0)} Func <double, double, double> rhs = (double x, double y) => y * (1.0 - y); Func <double, double, double> solution = (double y0, double x) => y0 / (y0 + (1.0 - y0) * Math.Exp(-x)); foreach (double y0 in new double[] { -0.1, 0.0, 0.4, 1.0, 1.6 }) { Console.WriteLine(y0); Interval r = Interval.FromEndpoints(0.0, 2.0); double y1 = FunctionMath.SolveOde(rhs, 0.0, y0, 2.0); Console.WriteLine(y1); Assert.IsTrue(TestUtilities.IsNearlyEqual(y1, solution(y0, 2.0))); } }