Пример #1
0
        public void CreatingPolinomial()
        {
            Polinomial polinomial     = new Polinomial(new double[] { 1, 2, 3 });
            int        expectedDegree = 2;

            Assert.AreEqual(expectedDegree, polinomial.Degree);
        }
Пример #2
0
        public void HashCode2()
        {
            Polinomial a = new Polinomial(new double[] { 2, 3, 4, 5 });
            Polinomial b = new Polinomial(new double[] { 5, 4, 3, 2 });

            Assert.IsTrue(a.GetHashCode() == b.GetHashCode());
        }
        public bool PolinomialEqualsTests(double[] coefs, int degree)
        {
            Polinomial firstPol  = new Polinomial(new double[] { 1, 2, 3 }, 2);
            Polinomial secondPol = new Polinomial(coefs, degree);

            return(firstPol.Equals(secondPol));
        }
Пример #4
0
        public void EqualityTest4()
        {
            Polinomial a = new Polinomial(new double[] { 2, 3, 4, 5 });
            Polinomial b = new Polinomial(new double[] { 2, 2, 4, 5 });

            Assert.IsTrue(a != b);
        }
Пример #5
0
        public void EqualsTest2()
        {
            Polinomial a = new Polinomial(new double[] { 2, 3, 4, 5 });
            Polinomial b = new Polinomial(new double[] { 2, 2, 4, 5 });

            Assert.IsFalse(a.Equals(b));
        }
Пример #6
0
        public void SomaDeContantesTest(double[] actualFist, double actualSecond, double[] expected)
        {
            var a = new Polinomial(actualFist.ToList());

            a.Multiplicar(actualSecond);
            Assert.IsTrue(expected.SequenceEqual(a.Polinomio.Values.ToList()));
        }
        public bool PolinomialEquityTests(double[] coefs1, int degree1, double[] coefs2, int degree2)
        {
            Polinomial firstPol  = new Polinomial(coefs1, degree1);
            Polinomial secondPol = new Polinomial(coefs2, degree2);

            return(firstPol == secondPol);
        }
Пример #8
0
        public void SomaTest(double[] actualFist, double[] actualSecond, double[] expected)
        {
            var a = new Polinomial(actualFist.ToList());
            var b = new Polinomial(actualSecond.ToList());

            a.Somar(b);
            Assert.IsTrue(expected.SequenceEqual(a.Polinomio.Values.ToList()));
        }
Пример #9
0
            public static Polinomial operator /(Polinomial a, Polinomial b)
            {
                Polinomial ib = new Polinomial(
                    b.xValue == 0 ? 0 : 1.0f / b.xValue,
                    b.pureValue == 0 ? 0 : 1.0f / b.pureValue);

                return(a * ib);
            }
Пример #10
0
        public void MultiplicationTest()
        {
            Polinomial a = new Polinomial(new double[] { 1, 1 });
            Polinomial b = new Polinomial(new double[] { 1, 1 });

            a *= b;
            Assert.IsTrue(new Polinomial(new double[] { 1, 2, 1 }) == a);
        }
Пример #11
0
        public void SubstractionTest()
        {
            Polinomial a = new Polinomial(new double[] { 2, 3, 4, 5 });
            Polinomial b = new Polinomial(new double[] { 5, 4, 3, 2 });
            Polinomial c = new Polinomial(new double[] { -3, -1, 1, 3 });

            a -= b;
            Assert.IsTrue(a == c);
        }
Пример #12
0
        public void SummingTest()
        {
            Polinomial a = new Polinomial(new double[] { 2, 3, 4, 5 });
            Polinomial b = new Polinomial(new double[] { 5, 4, 3, 2 });
            Polinomial c = new Polinomial(new double[] { 7, 7, 7, 7 });

            a += b;
            Assert.IsTrue(a == c);
        }
Пример #13
0
        public void SumOfTwoPolinomialsNustReturnExpectedResult(double[] first, double[] second, double[] expected)
        {
            Polinomial firstPolimomial          = new Polinomial(first);
            Polinomial secondPolimomial         = new Polinomial(second);
            Polinomial expectedSumOfPolinomials = new Polinomial(expected);

            Polinomial sumOfPolinomials = firstPolimomial + secondPolimomial;

            Assert.AreEqual(expectedSumOfPolinomials, sumOfPolinomials);
        }
Пример #14
0
        public void MultiplyingPolinomialsByZeroNumberMustReturnValidResult()
        {
            Polinomial polimomial         = new Polinomial(new double[] { 5, -3, 0, 9 });
            var        expectedPolimomial = new Polinomial(new double[] { 0, 0, 0, 0 });
            int        number             = 0;

            polimomial *= number;

            Assert.AreEqual(expectedPolimomial, polimomial);
        }
Пример #15
0
        public void MultiplyingPolinomialsByZNegativeNumberMustReturnValidResult()
        {
            Polinomial polimomial         = new Polinomial(new double[] { 5, -3, 0, 9 });
            var        expectedPolimomial = new Polinomial(new double[] { -15, 9, 0, -27 });
            int        number             = -3;

            polimomial *= number;

            Assert.AreEqual(expectedPolimomial, polimomial);
        }
Пример #16
0
        public void DividingPolinomialWithSmallerDegreeOnPolinomialWithBiggerDegreeMustReturnNull()
        {
            Polinomial firstPolinomial    = new Polinomial(new double[] { 3, -1, 1 });
            Polinomial secondPolinomial   = new Polinomial(new double[] { -1, 0, -7, 0, 10 });
            Polinomial expectedPolinomial = null;

            Polinomial dividingOfTwoPolinomials = firstPolinomial / secondPolinomial;

            Assert.AreEqual(expectedPolinomial, dividingOfTwoPolinomials);
        }
Пример #17
0
        public void DividingPolinomialOnZeroPolinomialMustReturnNull()
        {
            Polinomial firstPolinomial    = new Polinomial(new double[] { -1, 0, -7, 0, 10 });
            Polinomial secondPolinomial   = new Polinomial(new double[] { 0 });
            Polinomial expectedPolinomial = null;

            Polinomial dividingOfTwoPolinomials = firstPolinomial / secondPolinomial;

            Assert.AreEqual(expectedPolinomial, dividingOfTwoPolinomials);
        }
Пример #18
0
        public void DividingOfTwoPolinomialsMustReturnValidResult()
        {
            Polinomial firstPolinomial    = new Polinomial(new double[] { -1, 0, -7, 0, 10 });
            Polinomial secondPolinomial   = new Polinomial(new double[] { 3, -1, 1 });
            Polinomial expectedPolinomial = new Polinomial(new double[] { -27, 10, 10 });

            Polinomial dividingOfTwoPolinomials = firstPolinomial / secondPolinomial;

            Assert.AreEqual(expectedPolinomial, dividingOfTwoPolinomials);
        }
Пример #19
0
        public void MultiplayingOfTwoPolinomialsSameSizeMustReturnValidResult()
        {
            Polinomial firstPolinomial    = new Polinomial(new double[] { 5, -3, 0, 9 });
            Polinomial secondPolinomial   = new Polinomial(new double[] { 11, 6, -12, 3 });
            var        expectedPolinomial = new Polinomial(new double[] { 55, -3, -78, 150, 45, -108, 27 });

            var multiplayingOfTwoPolinomials = firstPolinomial * secondPolinomial;

            Assert.AreEqual(expectedPolinomial, multiplayingOfTwoPolinomials);
        }
Пример #20
0
        public void MultiplayingOfTwoPolinomialsDifferentSizeMustReturnValidResult()
        {
            Polinomial firstPolinomial    = new Polinomial(new double[] { 5, -3, 0, 9 });
            Polinomial secondPolinomial   = new Polinomial(new double[] { 11, 6, -12 });
            var        expectedPolinomial = new Polinomial(new double[] { 55, -3, -78, 135, 54, -108 });

            var multiplayingOfTwoPolinomials = firstPolinomial * secondPolinomial;

            Assert.AreEqual(expectedPolinomial, multiplayingOfTwoPolinomials);
        }
Пример #21
0
        public void DifferenceOfTwoPolinomialsNustReturnExpectedResult()
        {
            Polinomial firstPolimomial          = new Polinomial(new double[] { 5, -3, 0, 9 });
            Polinomial secondPolimomial         = new Polinomial(new double[] { 11, 6, -12 });
            Polinomial expectedSumOfPolinomials = new Polinomial(new double[] { -6, -9, 12, 9 });

            Polinomial sumOfPolinomials = firstPolimomial - secondPolimomial;

            Assert.AreEqual(expectedSumOfPolinomials, sumOfPolinomials);
        }
Пример #22
0
        public string Interpolacao()
        {
            // Quantida de pontos
            K = Pontos.Count - 1;
            var polinomial = new Polinomial();

            for (var i = 0; i < K; i++)
            {
                polinomial.Somar(ProdutorioL(i));
            }

            return(polinomial.ImprimirFormatado());
        }
        public void PolinomialMultiplicationTests(double[] coefs, int degree, double[] sumCoef, int sumDegree)
        {
            Polinomial firstPol  = new Polinomial(new double[] { 1, 2, 3 }, 2);
            Polinomial secondPol = new Polinomial(coefs, degree);

            Polinomial sumPol = firstPol * secondPol;

            Assert.AreEqual(sumPol.getDegree(), sumDegree);

            for (int i = 0; i < sumPol.getCoef().Length; i++)
            {
                Assert.AreEqual(sumPol.getCoef()[i], sumCoef[i], 0.1);
            }
        }
Пример #24
0
 private void btnEqual_Click(object sender, EventArgs e)
 {
     try
     {
         Polinomial p = new Polinomial(txtView.Text);
         txtView.Text = p.Answer(new string[0]);
         txtView.Tag  = "Answer";
     }
     catch
     {
         txtView.Text = "Error: Invalid terms.";
         txtView.Tag  = "Answer";
     }
 }
Пример #25
0
        public void TestAnsver()
        {
            Polinomial v = new Polinomial(new List <double>()
            {
                1, 2, 3
            });

            double expected = 11;
            double actual;

            actual = v.getAnsver(2);

            Assert.AreEqual(actual, expected);
        }
Пример #26
0
        private Polinomial ProdutorioL(int j)
        {
            Polinomial polinomial;

            // Caso especial para iniciação do polinomio
            // K == 1
            if (j != 0)
            {
                polinomial = new Polinomial(new[]
                {
                    Pontos[0].x * -1,
                    1
                });
                polinomial.Multiplicar(1 / (Pontos[j].x - Pontos[0].x));
            }
            else
            {
                // Quando é o primeiro
                // K = 1
                polinomial = new Polinomial(new[]
                {
                    Pontos[1].x * -1,
                    1
                });
                polinomial.Multiplicar(1 / (Pontos[j].x - Pontos[1].x));
            }

            for (var i = 1; i < K; i++)
            {
                if (i == j)
                {
                    continue;
                }

                polinomial.Multiplicar(new[]
                {
                    Pontos[i].x * -1,
                    1
                });
                polinomial.Multiplicar(1 / (Pontos[j].x - Pontos[i].x));
            }

            // Multiplicação de Y
            polinomial.Multiplicar(Pontos[j].y);

            return(polinomial);
        }
Пример #27
0
    public static Polinomial operator *(Polinomial a, Polinomial b)
    {
        Polinomial result = new Polinomial();

        for (int i = 0; i < a.coefficients.Count + b.coefficients.Count - 1; i++)
        {
            result.AddCoefficient(0d);
        }

        for (int i = 0; i < a.coefficients.Count; i++)
        {
            for (int j = 0; j < b.coefficients.Count; j++)
            {
                result[i + j] += (a[i] * b[j]);
            }
        }
        return(result);
    }
Пример #28
0
        public static float Solve(Equation equation)
        {
            Polinomial lhs = Solve(equation.lhs);
            Polinomial rhs = Solve(equation.rhs);

            //Console.WriteLine(lhs + " = " + rhs);

            float xTerms = lhs.xValue - rhs.xValue;
            float nTerms = rhs.pureValue - lhs.pureValue;

            if (xTerms == 0)
            {
                throw new Exception("No Xs left on equation");
            }

            //Console.WriteLine(xTerms + "x = " + nTerms);
            return(nTerms / xTerms);
        }
Пример #29
0
        public string Interpolacao()
        {
            var escalares = CalculaD();

            var polinomio = new Polinomial(escalares[0]);

            for (var i = 1; i < escalares.Count; i++)
            {
                var auxPoli = new Polinomial(-Pontos[0].x, 1);
                for (var j = 1; j < i; j++)
                {
                    auxPoli.Multiplicar(new [] { -Pontos[j].x, 1 });
                }
                auxPoli.Multiplicar(escalares[i]);
                polinomio.Somar(auxPoli);
            }

            return(polinomio.ImprimirFormatado());
        }
Пример #30
0
        public static Polinomial Solve(Mult mult)
        {
            Polinomial result = Solve(mult.term);

            foreach (var multOp in mult.multOp)
            {
                switch (multOp.operatorSymbol)
                {
                case "*":
                    result *= Solve(multOp.term);
                    break;

                case "/":
                    result /= Solve(multOp.term);
                    break;
                }
            }
            return(result);
        }
Пример #31
0
 private void Sort()
 {
     foreach (Monomial monomial in this.left)
     {
         if (!monomial.IsMonomial)
         {
             this.right -= monomial;
             this.left.Remove(monomial);
         }
     }
     foreach (Monomial monomial in this.right)
     {
         if (monomial.IsMonomial)
         {
             this.left -= monomial;
             this.right.Remove(monomial);
         }
     }
 }
Пример #32
0
 public Equation(Polinomial left, Polinomial right)
 {
     this.left = left;
     this.right = right;
 }