public void Calculate_Antano_Limit_1() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new Sine {Aparam = 4, Bparam = 0} } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, PolynomialDegree = 1, } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(4.0); }
public void CalculateLimit_AndReturnsCorrectLimit_9_StringParse() { string numeratorString = "x^(1/5)"; string denominatorString = "x^(1/3)"; var normalizedFunction = new NormalizedFunction { Numerator = StringToSummand.Parse(numeratorString), Denominator = StringToSummand.Parse(denominatorString), }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.PositiveInfinity); }
public void CalculateLimit_MKD_67_16_StringParse() { string numeratorString = "1-cos(Pi*x+2)"; string denominatorString = "1"; var normalizedFunction = new NormalizedFunction { Numerator = StringToSummand.Parse(numeratorString), Denominator = StringToSummand.Parse(denominatorString), }; var result = LimitCalculator.CalculateLimit(normalizedFunction, -2 / Math.PI); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(0); }
public void CalculateLimit_MKD_67_1() { var numerator = new List<Summand> { new Summand { Coefficient = 5.0, PolynomialDegree = 2 }, new Summand { Coefficient = -4.0, PolynomialDegree = 1 }, new Summand { Coefficient = -1.0 } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, PolynomialDegree = 1 }, new Summand { Coefficient = -1.0, } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 1); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(6.0); }
public void CalculatePoviloLimit1() { var numerator = new List<Summand> { new Summand { Coefficient = -1.0, Multiplicands = new List<IElementaryFunction> { new PowerFunction { Aparam = 1, Bparam = 0, PowerNumerator = 1, PowerDenominator = 2} } }, new Summand { Coefficient = 5.0, PolynomialDegree = 1, } }; var denominator = new List<Summand> { new Summand { Coefficient = 1 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 1); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(4); }
public void CalculateLimit_MKD_69_34() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new Sine { Aparam = 7 * Math.PI } } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new Sine { Aparam = 2 * Math.PI } } } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 1); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(-3.5); }
public void CalculateLimit_MKD_69_33() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new Cosine { Aparam = 1 } }, SumsRaisedToPower = new List<SumRaisedToPower> { new SumRaisedToPower { Degree = 1, Sum = new List<Summand> { new Summand { Coefficient = 1, Multiplicands = new List<IElementaryFunction> { new ExponentialFunction { Aparam = 7 } } }, new Summand { Coefficient = -1, Multiplicands = new List<IElementaryFunction> { new ExponentialFunction { Aparam = 2 } } } } } } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new Sine { Aparam = 1 } } } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0.0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(5); }
public void CalculateLimit_MKD_69_27() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new Cosine { Aparam = 3 } } }, new Summand { Coefficient = -1.0, Multiplicands = new List<IElementaryFunction> { new Cosine { Aparam = 7 } } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, PolynomialDegree = 2 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0.0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(20); }
public static LimitResult CalculateLimit(NormalizedFunction normalizedFunction, double argument) { var raisedNumerator = normalizedFunction.Numerator.SelectMany(RaiseSumsToPower); var raisedDenominator = normalizedFunction.Denominator.SelectMany(RaiseSumsToPower); if (!MathHelper.IsZero(argument)) { raisedNumerator = TransformArgumentToZero(raisedNumerator, argument); raisedDenominator = TransformArgumentToZero(raisedDenominator, argument); } var expandedNumerator = PerformTaylorExpansion(raisedNumerator); var expandedDenominator = PerformTaylorExpansion(raisedDenominator); var numeratorMinPolynomialWithoutO = expandedNumerator.FirstOrDefault(s => s.LittleODegree == 0); var denominatorMinPolynomialWithoutO = expandedDenominator.FirstOrDefault(s => s.LittleODegree == 0); if (denominatorMinPolynomialWithoutO == null) { return new LimitResult { LimitResultType = LimitResultType.DoesNotExist, }; } if (numeratorMinPolynomialWithoutO == null) { return new LimitResult { LimitResultType = LimitResultType.RealNumber, Value = 0 }; } var degreeNumerator = numeratorMinPolynomialWithoutO.PolynomialDegree * denominatorMinPolynomialWithoutO.PolynomialDegreeDenominator - denominatorMinPolynomialWithoutO.PolynomialDegree * numeratorMinPolynomialWithoutO.PolynomialDegreeDenominator; var degreeDenominator = denominatorMinPolynomialWithoutO.PolynomialDegreeDenominator * numeratorMinPolynomialWithoutO.PolynomialDegreeDenominator; if (degreeNumerator == 0) { return new LimitResult { LimitResultType = LimitResultType.RealNumber, Value = numeratorMinPolynomialWithoutO.Coefficient / denominatorMinPolynomialWithoutO.Coefficient }; } var gcd = MathHelper.GreatestCommonDivisor(degreeNumerator >= 0 ? degreeNumerator : -degreeNumerator, degreeDenominator); degreeNumerator /= gcd; degreeDenominator /= gcd; if (degreeNumerator > 0 && (degreeDenominator == 1 || degreeNumerator % 2 == 0)) { return new LimitResult { LimitResultType = LimitResultType.RealNumber, Value = 0 }; } if (degreeNumerator > 0 && degreeNumerator % 2 == 1) { return new LimitResult { LimitResultType = LimitResultType.DoesNotExist, }; } degreeNumerator = -degreeNumerator; if (degreeNumerator % 2 == 1) { return new LimitResult { LimitResultType = LimitResultType.DoesNotExist }; } if (numeratorMinPolynomialWithoutO.Coefficient * denominatorMinPolynomialWithoutO.Coefficient > 0) { return new LimitResult { LimitResultType = LimitResultType.PositiveInfinity }; } return new LimitResult { LimitResultType = LimitResultType.NegativeInfinity }; }
public void Calculate_Antano_Limit_12_sin() { var numerator = new List<Summand> { new Summand { Coefficient = -1.0, Multiplicands = new List<IElementaryFunction> { new Sine {Aparam = 1, Bparam = 0} } }, new Summand { Coefficient = 1.0, } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new Cosine {Aparam = 1, Bparam = 0}, new Cosine {Aparam = 1, Bparam = 0} } } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, Math.PI/2); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(0.5); }
public void Kuznecov_15_2() { var numerator = new List<Summand> { new Summand { Coefficient=1.0 }, new Summand { Coefficient=1.0, Multiplicands = new List<IElementaryFunction> { new Sine { Aparam = 1.0, Bparam=0} }, PolynomialDegree = 1 }, new Summand { Coefficient = -1.0, Multiplicands = new List<IElementaryFunction> { new Cosine { Aparam = 2.0, Bparam = 0} } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1, SumsRaisedToPower = new List<SumRaisedToPower> { new SumRaisedToPower { Degree = 2, Sum = new List<Summand> { new Summand { Coefficient = 1, Multiplicands = new List<IElementaryFunction> { new Sine {Aparam = 1.0, Bparam = 0} } } } } } } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(3.0); }
public void CalculateLimit_MKD_74_5() { var numerator = new List<Summand> { new Summand { Multiplicands = new List<IElementaryFunction> { new PowerFunction { Aparam = 1, Bparam = 32, PowerNumerator = 1, PowerDenominator = 5 } } }, new Summand { Coefficient = -2 } }; var denominator = new List<Summand> { new Summand { PolynomialDegree = 1 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(1.0/80); }
public void CalculateLimit_AndReturnsCorrectLimit_9() { var numerator = new List<Summand> { new Summand { Multiplicands = new List<IElementaryFunction> { new PowerFunction() {Aparam = 1, PowerNumerator = 1, PowerDenominator = 5} } } }; var denominator = new List<Summand> { new Summand { Multiplicands = new List<IElementaryFunction> { new PowerFunction {Aparam = 1, PowerNumerator = 1, PowerDenominator = 3} } } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.PositiveInfinity); }
public void CalculateLimit_AndReturnsCorrectLimit_8() { var numerator = new List<Summand> { new Summand() }; var denominator = new List<Summand> { new Summand { Multiplicands = new List<IElementaryFunction> { new Sine {Aparam = 1} } } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.DoesNotExist); }
public void CalculateLimit_AndReturnsCorrectLimit_7() { var numerator = new List<Summand> { new Summand() }; var denominator = new List<Summand> { new Summand { Coefficient = -1, PolynomialDegree = 2 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.NegativeInfinity); }
public void CalculateLimit_AndReturnsCorrectLimit_6() { var numerator = new List<Summand> { new Summand() }; var denominator = new List<Summand> { new Summand { PolynomialDegree = 1 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.DoesNotExist); }
public void CalculateLimit_AndReturnsCorrectLimit_5() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new Sine() { Aparam = 1.0, Bparam = 3 } } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); MathHelper.AreApproximatelyEqual(result.Value, 0.141, 0.005).Should().BeTrue(); }
public void CalculateLimit_AndReturnsCorrectLimit_4() { var numerator = new List<Summand> { new Summand { Coefficient = 2.0, PolynomialDegree = 1 } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, PolynomialDegree = 1 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(2.0); }
public void CalculateLimit_AndReturnsCorrectLimit_3() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, PolynomialDegree = 3, Multiplicands = new List<IElementaryFunction> { new Sine { Aparam = 1 } }, SumsRaisedToPower = new List<SumRaisedToPower> { new SumRaisedToPower { Degree = 2, Sum = new List<Summand> { new Summand { Coefficient = 1.0, PolynomialDegree = 3 }, new Summand { Coefficient = 3.0, SumsRaisedToPower = new List<SumRaisedToPower> { new SumRaisedToPower { Degree = 2, Sum = new List<Summand> { new Summand { Coefficient = 1, PolynomialDegree = 1 }, new Summand { Coefficient = 1, Multiplicands = new List<IElementaryFunction> { new Sine { Aparam = 1 } } } } } } } } } } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(0.0); }
public void CalculateLimit_MKD_74_2() { var numerator = new List<Summand> { new Summand { PolynomialDegree = 4 }, new Summand { Coefficient = -1, PolynomialDegree = 3 }, new Summand { PolynomialDegree = 2 }, new Summand { Coefficient = -3, PolynomialDegree = 1 }, new Summand { Coefficient = 3, } }; var denominator = new List<Summand> { new Summand { PolynomialDegree = 3 }, new Summand { Coefficient = -1, PolynomialDegree = 2 }, new Summand { Coefficient = -1, PolynomialDegree = 1 }, new Summand { Coefficient = 1 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 1); result.LimitResultType.Should().Be(LimitResultType.PositiveInfinity); }
public void CalculateLimit_MKD_67_16() { var numerator = new List<Summand> { new Summand { Coefficient = 1 }, new Summand { Coefficient = -1, Multiplicands = new List<IElementaryFunction> { new Cosine { Aparam = Math.PI, Bparam = 2} } }, }; var denominator = new List<Summand> { new Summand { Coefficient = 1 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, -2 / Math.PI); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(0); }
public void CalculateLimit_AndReturnsCorrectLimit_10() { var numerator = new List<Summand> { new Summand { Multiplicands = new List<IElementaryFunction> { new LogarithmicFunction {Aparam = 3, Bparam = 5} } }, new Summand { Coefficient = -Math.Log(5) }, new Summand { Coefficient = -3.0/5, PolynomialDegree = 1 }, new Summand { Coefficient = 9.0/25/2, PolynomialDegree = 2 } }; var denominator = new List<Summand> { new Summand { PolynomialDegree = 3 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(27.0/125/3); }
public void CalculateLimit_MKD_69_33_StringParse() { string numeratorString = "(cos(x)*(e^(7x)-e^(2x)))"; string denominatorString = "sin(x)"; var normalizedFunction = new NormalizedFunction { Numerator = StringToSummand.Parse(numeratorString), Denominator = StringToSummand.Parse(denominatorString) }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0.0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(5); }
public void CalculateLimit_MKD_67_1_StringParse() { string numeratorString = "((5*x^2)-4*x-1)"; string denominatorString = "(x-1)"; // var a = StringToSummand.FindPolynomialDegree("(5*x^2)"); var normalizedFunction = new NormalizedFunction { Numerator = StringToSummand.Parse(numeratorString), Denominator = StringToSummand.Parse(denominatorString) }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 1); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(6.0); }
public void Kuznecov_15_3() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, PolynomialDegree = 3 }, new Summand { Coefficient = 1.0, }, }; var denominator = new List<Summand> { new Summand { Coefficient=1.0, Multiplicands = new List<IElementaryFunction> { new Sine { Aparam = 1.0, Bparam = 1.0} } } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, -1); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(3.0); }
public void CalculateLimit_MKD_68_14() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new PowerFunction { Aparam = 1.0, Bparam = 1.0, PowerNumerator = 1, PowerDenominator = 2 } }, SumsRaisedToPower = new List<SumRaisedToPower> { new SumRaisedToPower { Degree = 1, Sum = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new PowerFunction { Aparam = 1.0, Bparam = 1.0, PowerNumerator = 1, PowerDenominator = 2 }, } }, new Summand { Coefficient = -1.0, Multiplicands = new List<IElementaryFunction> { new PowerFunction { Aparam = -1.0, Bparam = 1.0, PowerNumerator = 1, PowerDenominator = 2 }, } } } } } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new PowerFunction {Aparam = 1.0, Bparam = 0, PowerNumerator = 1, PowerDenominator = 5}, } } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 0.0); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(0.0); }
public void CalculateLimit_MKD_68_10() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new PowerFunction { Aparam = 1.0, Bparam = -1.0, PowerNumerator = 1, PowerDenominator = 2 } } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new PowerFunction {Aparam = 1.0, Bparam = -1.0, PowerNumerator = 1, PowerDenominator = 3}, new PowerFunction {Aparam = 1.0, Bparam = 1.0, PowerNumerator = 1, PowerDenominator = 3} } } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 1.0); result.LimitResultType.Should().Be(LimitResultType.DoesNotExist); }
public void Calculate_Antano_Limit_8_ln() { var numerator = new List<Summand> { new Summand { Coefficient = 1.0, Multiplicands = new List<IElementaryFunction> { new LogarithmicFunction {Aparam = 1, Bparam = 0} } }, new Summand { Coefficient = -1.0, Multiplicands = new List<IElementaryFunction> { new LogarithmicFunction {Aparam = 0, Bparam = 11} } } }; var denominator = new List<Summand> { new Summand { Coefficient = 1.0, PolynomialDegree = 1 }, new Summand { Coefficient = -11.0 } }; var normalizedFunction = new NormalizedFunction { Numerator = numerator, Denominator = denominator }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 11); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(1.0/11.0); }
private void CountLimit_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(NuText.Text) || string.IsNullOrWhiteSpace(DeText.Text) || string.IsNullOrWhiteSpace(XgoTo.Text)) { ErrorBox.Text = "Fields can't be empty"; return; } try { var normalizedFunction = new NormalizedFunction { Numerator = Stack_Numerator.ToList(), Denominator = Stack_Denominator.ToList() }; var result = LimitCalculator.CalculateLimit(normalizedFunction, Convert.ToDouble(XgoTo.Text)); if(result.LimitResultType == LimitResultType.RealNumber) Limit_Answer.Text = Convert.ToString(result.Value); if (result.LimitResultType == LimitResultType.DoesNotExist) Limit_Answer.Text = "Not exist"; if (result.LimitResultType == LimitResultType.PositiveInfinity) Limit_Answer.Text = "Positive infinity"; if (result.LimitResultType == LimitResultType.NegativeInfinity) Limit_Answer.Text = "Negative infinity"; } catch(LimitDoesNotExistException) { Limit_Answer.Text = "Not exist"; } catch(Exception ex) { ErrorBox.Text = ex.Message; } finally { CountLimit.Enabled = false; } }
public void CalculatePoviloLimit4() { var numerator = new List<Summand> { new Summand { Coefficient = 1, PolynomialDegree = 2, }, new Summand { Coefficient = 1, PolynomialDegree = 1, } }; var denominator = new List<Summand> { new Summand { Coefficient = 1 } }; var normalizedFunction = new NormalizedFunction { Denominator = denominator, Numerator = numerator, }; var result = LimitCalculator.CalculateLimit(normalizedFunction, 10); result.LimitResultType.Should().Be(LimitResultType.RealNumber); result.Value.Should().Be(110.0); }