public void TestSimpsonRule() { SimpsonRule algorithm = new SimpsonRule(); Assert.That( algorithm.IntegrateThreePoint(TargetFunctionA, StartA, StopA), NumericIs.AlmostEqualTo(TargetAreaA, 1.7e-1), "Direct (2 Partitions)"); Assert.That( algorithm.IntegrateComposite(TargetFunctionA, StartA, StopA, 2), NumericIs.AlmostEqualTo(TargetAreaA, 1.7e-1), "Composite 2 Partitions"); Assert.That( algorithm.IntegrateComposite(TargetFunctionA, StartA, StopA, 6), NumericIs.AlmostEqualTo(TargetAreaA, 1.2e-1), "Composite 6 Partitions"); Assert.That( algorithm.IntegrateComposite(TargetFunctionA, StartA, StopA, 10), NumericIs.AlmostEqualTo(TargetAreaA, 8e-3), "Composite 10 Partitions"); Assert.That( algorithm.IntegrateComposite(TargetFunctionA, StartA, StopA, 50), NumericIs.AlmostEqualTo(TargetAreaA, 8e-6), "Composite 50 Partitions"); Assert.That( algorithm.IntegrateComposite(TargetFunctionA, StartA, StopA, 1000), NumericIs.AlmostEqualTo(TargetAreaA, 5e-11), "Composite 1000 Partitions"); }
public static float3 Integral(float4[] cp, float tOld, float tNew) { float intX = (float)SimpsonRule.IntegrateThreePoint(x => cp[0].x * m.pow(1 - x, 4) + 4f * cp[1].x * x * m.pow(1 - x, 3) + 6f * cp[2].x * m.pow(x, 2) * m.pow(1 - x, 2) + 4f * cp[3].x * m.pow(x, 4), tOld, tNew); float intY = (float)SimpsonRule.IntegrateThreePoint(x => cp[0].y * m.pow(1 - x, 4) + 4f * cp[1].y * x * m.pow(1 - x, 3) + 6f * cp[2].y * m.pow(x, 2) * m.pow(1 - x, 2) + 4f * cp[3].y * m.pow(x, 4), tOld, tNew); float intZ = (float)SimpsonRule.IntegrateThreePoint(x => cp[0].z * m.pow(1 - x, 4) + 4f * cp[1].z * x * m.pow(1 - x, 3) + 6f * cp[2].z * m.pow(x, 2) * m.pow(1 - x, 2) + 4f * cp[3].z * m.pow(x, 4), tOld, tNew); return(new float3(intX, intY, intZ)); }
public void SimpsonRuleSupportsThreePointIntegration() { Assert.AreEqual( TargetAreaA, SimpsonRule.IntegrateThreePoint(TargetFunctionA, StartA, StopA), 0.2 * TargetAreaA, "Direct (2 Partitions)"); }
public static double CalculateStrictValue(FuzzyNumber fuzzyNumber) { var leftX = fuzzyNumber.M - fuzzyNumber.L; var leftValue = fuzzyNumber.L; var rightX = fuzzyNumber.U - fuzzyNumber.M; var rightValue = fuzzyNumber.U; var finalX = leftX - rightX; var finalValue = rightValue + leftValue; return(SimpsonRule.IntegrateThreePoint(x => 0.5 * (finalX * x + finalValue), 0.0, 1.0)); }
/// <summary> /// Остаток на складе /// </summary> /// <param name="lb"></param> /// <param name="ub"></param> /// <param name="t"></param> /// <returns></returns> double I(double lb, double ub, double t) { double rez = SimpsonRule.IntegrateThreePoint(x => D(x), lb, ub) - SimpsonRule.IntegrateThreePoint(x => D(x), lb, t); return(rez); }
static void Main(string[] args) { /// Git test project Console.WriteLine("ASP joined the project"); /// Simpsons Rule //--------------------------------------------- Console.WriteLine("Simpson integration"); Console.WriteLine(""); // Composite approximation with 4 partitions double composite = SimpsonRule.IntegrateComposite(x => x * x, 0.0, 10.0, 4); // Approximate value using IntegrateComposite with 4 partitions is: 333.33333333333337 Console.WriteLine("Approximate value using IntegrateComposite with 4 partitions is: " + composite); // Three point approximation double threePoint = SimpsonRule.IntegrateThreePoint(x => x * x, 0.0, 10.0); // Approximate value using IntegrateThreePoint is: 333.333333333333 Console.WriteLine("Approximate value using IntegrateThreePoint is: " + threePoint); /// Gauss-Legendre integration //--------------------------------------------- Console.WriteLine(""); Console.WriteLine("Gauss-Legendre integration"); Console.WriteLine(""); // Create a 5-point Gauss-Legendre rule over the integration interval [0, 10] GaussLegendreRule rule = new GaussLegendreRule(0.0, 10.0, 5); double sum = 0; // Will hold the approximate value of the integral for (int i = 0; i < rule.Order; i++) // rule.Order = 5 { // Access the ith abscissa and weight sum += rule.GetWeight(i) * rule.GetAbscissa(i) * rule.GetAbscissa(i); } // Approximate value is: 333.333333333333 Console.WriteLine("Approximate value is: " + sum); // The order of the rule is: 5 Console.WriteLine("The order of the rule is: " + rule.Order); // 1D integration using a 5-point Gauss-Legendre rule over the integration interval [0, 10] double integrate1D = GaussLegendreRule.Integrate(x => x * x * x, 0.0, 10.0, 5); // Approximate value of the 1D integral is: 333.333333333333 Console.WriteLine("Approximate value of the 1D integral is: " + integrate1D); // 2D integration using a 5-point Gauss-Legendre rule over the integration interval [0, 10] X [1, 2] double integrate2D = GaussLegendreRule.Integrate((x, y) => (x * x) * (y * y), 0.0, 10.0, 1.0, 2.0, 5); // Approximate value of the 2D integral is: 777.777777777778 Console.WriteLine("Approximate value of the 2D integral is: " + integrate2D); Console.ReadLine(); }