public void Equals_PolynomAndNull_False()
        {
            Polynom a = new Polynom();
            Polynom b = null;

            Assert.IsFalse(a.Equals(b));
        }
예제 #2
0
 public void Add()
 {
     Polynom polynom1 = new Polynom(coeffPolynom1);
     Polynom polynom2 = new Polynom(coeffPolynom2);
     Polynom expectedPolynom = new Polynom(coeffAdd);
     Assert.That(polynom1 + polynom2, Is.EqualTo(expectedPolynom));
 }
예제 #3
0
 public void Clone()
 {
     Polynom polynom1 = new Polynom(coeffPolynom1);
     Polynom polynom2 = (Polynom) polynom1.Clone();
     Assert.That(polynom1.Equals(polynom2), Is.True);
     Assert.That(ReferenceEquals(polynom1, polynom2), Is.False);
 }
예제 #4
0
 public void Mul()
 {
     Polynom polynom1 = new Polynom(coeffPolynom1);
        Polynom polynom2 = new Polynom(coeffPolynom2);
        Polynom expectedPolynom = new Polynom(coeffMul);
        Assert.That(polynom2 * polynom1, Is.EqualTo(expectedPolynom));
 }
        public void Equals_EquivalentPolynomials_True()
        {
            double[] coefficients = new double[] { 1, 2, 3, 4, 5 };
            Polynom a = new Polynom(coefficients);
            Polynom b = new Polynom(coefficients);

            Assert.IsTrue(a.Equals(b));
        }
        public void Test_GetCoefficients()
        {
            double[] coefficients = new double[] { 1, 2, 3, 4, 5 };
            Polynom polynom = new Polynom(coefficients);

            IStructuralEquatable coeff = coefficients;
            Assert.IsTrue(coeff.Equals(polynom.GetCoefficients(), StructuralComparisons.StructuralEqualityComparer));
        }
        public void Equals_InequivalentPolynomials_False()
        {
            double[] coefficientsA = new double[] { 1, 2, 3, 4, 5 };
            double[] coefficientsB = new double[] { 1, 2, 3, 3, 5 };
            Polynom a = new Polynom(coefficientsA);
            Polynom b = new Polynom(coefficientsB);

            Assert.IsFalse(a.Equals(b));
        }
        public void Constructor_Coefficietn2Degree5_MonomialDgree5()
        {
            Polynom polynom = new Polynom(2, 5);

            double[] expected = new double[] { 0, 0, 0, 0, 0, 2 };

            IStructuralEquatable actual = polynom.GetCoefficients();
            Assert.IsTrue(actual.Equals(expected, StructuralComparisons.StructuralEqualityComparer));
        }
        public void Constructor_WithoutParameters_0()
        {
            Polynom polynom = new Polynom();

            double[] expected = new double[] { 0 };

            IStructuralEquatable actual = polynom.GetCoefficients();
            Assert.IsTrue(actual.Equals(expected, StructuralComparisons.StructuralEqualityComparer));
        }
예제 #10
0
 public void EqualsFunction()
 {
     double[] koeff = new double[a.Degree+1];
     for (int i = 0; i < koeff.Length; i++)
     {
         koeff[i] = a[i];
     }
     Polynom a1 =new Polynom(koeff);
     Assert.IsTrue(a.Equals(a1));
 }
예제 #11
0
    static void Main()
    {
        Polynom p1 = new Polynom(5, 1, 1);
        Polynom p2 = new Polynom(1, 1);

        Console.WriteLine("P1: {0}", p1);
        Console.WriteLine("P2: {0}", p2);

        Console.WriteLine("P3: {0}", p1 + p2);
    }
        public void SubstituteVariableValue()
        {
             double[] coefficients = new double[] { 1, 2, 3, 4, 5 };
             double x = 2;
             Polynom polynom = new Polynom(coefficients);

             double expected = 129;
             double actual = polynom.SubstituteVariableValue(x);

             Assert.AreEqual(expected, actual);
        }
        public void OperatorMultiplicationTest()
        {
            double[] arr1 = { 1.5, 2.5, 3.5, 4.5 };
            double[] arr2 = { 1.5, 2.5 };

            Polynom p1 = new Polynom(arr1);
            Polynom p2 = new Polynom(arr2);
            Polynom p  = p1 * p2;

            double[] expected = { 2.25, 7.5, 11.5, 15.5, 11.25 };

            CollectionAssert.AreEqual(expected, p.Coefficients);
        }
예제 #14
0
        public void Test2_NumberPolynom()
        {
            // arrange
            Polynom expected = new Polynom(3, 3, 3, 3);

            // act
            Polynom p1 = new Polynom(1, 1, 1, 1);

            p1 = 3 * p1;

            // assert
            Assert.AreEqual(expected, p1);
        }
예제 #15
0
        static void Main(string[] args)
        {
            Polynom p1 = new Polynom(1, 2, 3);
            Polynom p2 = new Polynom(1, 2, 2);
            Polynom p3 = p1 - p2;

            /* for(int i = 0; i <= p3.Degree; i++)
             * {
             *   Console.WriteLine(p3[i]);
             * }
             */
            Console.WriteLine(p1 != p2);
        }
        public void OperatorDivisionTest()
        {
            double[] arr1 = { -81, 0, 12, 1 };
            double[] arr2 = { 3, 1 };

            Polynom p1 = new Polynom(arr1);
            Polynom p2 = new Polynom(arr2);
            Polynom p  = p1 / p2;

            double[] expected = { -27, 9, 1 };

            CollectionAssert.AreEqual(expected, p.Coefficients);
        }
예제 #17
0
        public void Test1_PolynomNumber()
        {
            // arrange
            Polynom expected = new Polynom(2, 2, 2, 2);

            // act
            Polynom p1 = new Polynom(1, 1, 1, 1);

            p1 *= 2;

            // assert
            Assert.AreEqual(expected, p1);
        }
        public void OperatorMinusTest()
        {
            double[] arr1 = { 1.5, 2.5, 3.5, 4.5 };
            double[] arr2 = { 1.5, 2.5 };

            Polynom p1 = new Polynom(arr1);
            Polynom p2 = new Polynom(arr2);
            Polynom p  = p1 - p2;

            double[] expected = { 0.0, 0.0, 3.5, 4.5 };

            CollectionAssert.AreEqual(expected, p.Coefficients);
        }
예제 #19
0
        static void Main(string[] args)
        {
            double[] a = { 7, 5, 3 };
            var      p = new Polynom(a);
            // y = 3x^2 + 5x + 7

            var y0 = p.Value(0); // 7
            var y1 = p.Value(1); // 15
            var y5 = p.Value(5); // 107

            Console.WriteLine("Конец!");
            Console.ReadLine();
        }
예제 #20
0
        public override IDualSurfaceCurve[] GetPlaneIntersection(PlaneSurface pl, double umin, double umax, double vmin, double vmax, double precision)
        {
            if (Precision.IsPerpendicular(pl.Normal, zAxis, false))
            {
                // two lines along the cylinder axis
                Plane               lower = new Plane(location, zAxis);
                GeoPoint2D          sp2d  = lower.Project(pl.Location);
                GeoVector2D         dir2d = lower.Project(pl.Normal).ToLeft();
                GeoPoint2D[]        ips   = Geometry.IntersectLC(sp2d, dir2d, GeoPoint2D.Origin, xAxis.Length);
                IDualSurfaceCurve[] res   = new IDualSurfaceCurve[ips.Length];
                for (int i = 0; i < ips.Length; i++)
                {
                    GeoPoint p   = lower.ToGlobal(ips[i]);
                    Line     l3d = Line.TwoPoints(p, p + zAxis);
                    res[i] = new DualSurfaceCurve(l3d, this, new Line2D(this.PositionOf(l3d.StartPoint), this.PositionOf(l3d.EndPoint)), pl, new Line2D(pl.PositionOf(l3d.StartPoint), pl.PositionOf(l3d.EndPoint)));
                }
                return(res);
            }
            else
            {
                // an ellipse
                GeoPoint2D[] cnts = pl.GetLineIntersection(location, zAxis);
                if (cnts.Length == 1)
                {   // there must be exactly one intersection
                    GeoPoint  cnt       = pl.PointAt(cnts[0]);
                    GeoVector minorAxis = pl.Normal ^ zAxis;
                    minorAxis.Length = xAxis.Length;
                    GeoVector majorAxis = minorAxis ^ pl.Normal;
                    Polynom   impl      = GetImplicitPolynomial();
                    Polynom   toSolve   = impl.Substitute(new Polynom(majorAxis.x, "u", cnt.x, ""), new Polynom(majorAxis.y, "u", cnt.y, ""), new Polynom(majorAxis.z, "u", cnt.z, ""));
                    double[]  roots     = toSolve.Roots();
                    // there must be two roots
                    majorAxis = roots[0] * majorAxis;

                    Ellipse elli = Ellipse.Construct();
                    elli.SetEllipseCenterAxis(cnt, majorAxis, minorAxis);

                    GeoPoint2D[] fpnts = new GeoPoint2D[5];
                    for (int i = 0; i < 5; i++)
                    {
                        fpnts[i] = PositionOf(elli.PointAt(i / 6.0));
                    }
                    Ellipse2D e2d = Ellipse2D.FromFivePoints(fpnts); // there should be a better way to calculate the 2d ellipse, but the following is wrong:
                    // Ellipse2D e2d = new Ellipse2D(GeoPoint2D.Origin, PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector());
                    // and principal axis doesn't yield the correct result either
                    // Geometry.PrincipalAxis(PositionOf(cnt + majorAxis).ToVector(), PositionOf(cnt + minorAxis).ToVector(), out GeoVector2D maj, out GeoVector2D min);
                    return(new IDualSurfaceCurve[] { new DualSurfaceCurve(elli, this, e2d, pl, pl.GetProjectedCurve(elli, 0.0)) });
                }
            }
            return(new IDualSurfaceCurve[0]);
        }
        public void Differential_Returns_correct_Polynom()
        {
            //y = 7 + 5x + 3x^2
            var          p           = new Polynom(7, 5, 3);
            const double expected_a0 = 5;
            const double expected_a1 = 3 * 2;

            // diff_y = 5 + 6x
            var diff_p = p.GetDifferential();

            Assert.IsNotNull(diff_p);
            Assert.AreEqual(expected_a0, diff_p[0]);
            Assert.AreEqual(expected_a1, diff_p[1]);
        }
예제 #22
0
        public double GetInputPower(int rpm)
        {
            var x_n = DynamicPerformanceCurves.Select(x => (double)x.Rpm).ToArray();
            var y_P = DynamicPerformanceCurves.Select(x => x.PowerInput).ToArray();

            if (x_n.Count() != y_P.Count())
            {
                throw new ArgumentException("Angegebene drehzahlabhängige Leistungsdaten unplausibel.");
            }

            var p = Polynom.Polyfit(x_n, y_P, 2);

            return(p.Polyval(rpm));
        }
예제 #23
0
 public Polynom MultiplyWithYield(double[] leftCoeff, double[] rightCoeff)
 {
     Polynom left = new Polynom(leftCoeff);
     Polynom right = new Polynom(rightCoeff);
     if (leftCoeff.Length == 1)
     {
         return leftCoeff[0]*right;
     }
     if (rightCoeff.Length == 1)
     {
         return left*rightCoeff[0];
     }
     return left * right;
 }
예제 #24
0
        public void BeginningValues()
        {
            driver.Navigate().GoToUrl(URL);
            Polynom polynom = new Polynom(driver);

            Assert.That(polynom.DisplayedTable, Is.True);
            Assert.That(polynom.DisplayedFastFunctionInput, Is.True);
            Assert.That(polynom.DisplayedVectorPol, Is.True);
            Assert.That(polynom.DisplayedFastVectorInput, Is.True);
            Assert.That(polynom.DisplayedCriterious, Is.True);
            Assert.That(polynom.DisplayedBtnFind, Is.True);
            //Assert.That(polynom.TitleResValue(), Is.EqualTo(BEGIN_TITLE_VALUE));
            //Assert.That(polynom.PolynomResValue, Is.EqualTo(BEGIN_RES_VALUE));
        }
        public void Polynoms()
        {
            RealFunc f = (double x) => 1.0 / (1.0 + x * x);
            double   a = -9, b = 5;

            using (StreamWriter fs = new StreamWriter("Runge.txt"))
            {
                for (int i = 1; i < 30; i++)
                {
                    Polynom p = Polynom.Lag(f, i - 1, a, b);
                    fs.WriteLine($"{i} {FuncMethods.RealFuncMethods.NormDistanceС(f,p.Value,a,b)} {FuncMethods.RealFuncMethods.NormDistance(f, p.Value, a, b)}");
                }
            }
        }
예제 #26
0
        public void Level3_PolynomDegree()
        {
            var a1 = new Polynom()
            {
                coefficients = new double[] { 5, 8 }
            };

            var a3 = m.Degree(a1, 3);

            Assert.IsTrue(
                a3.coefficients[0] == 125 &&
                a3.coefficients[1] == 600 &&
                a3.coefficients[2] == 960 &&
                a3.coefficients[3] == 512);
        }
예제 #27
0
        public void PolynomTest05()
        {
            //arrange
            int[]   test_array  = { 49, -17, 9, 7, 21, -5, -15, -7 };
            int[]   test_array2 = { -23, 82, 301, -45 };
            int[]   exp_array   = { 26, 65, 310, -38, 21, -5, -15, -7 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);
            Polynom expected    = new Polynom(exp_array);
            //act
            Polynom result = p1 + p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #28
0
        public void PolynomTest06()
        {
            //arrange
            int[]   test_array  = { 49, -17, 9, 7, 21, -5, -15, -7 };
            int[]   test_array2 = { -23, 82, 301, -45 };
            int[]   exp_array   = { 72, -99, -292, 52, 21, -5, -15, -7 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);
            Polynom expected    = new Polynom(exp_array);
            //act
            Polynom result = p1 - p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #29
0
        private Polynom ReadPolynom(double [] coeffs, int degree)
        {
            Console.WriteLine("Polinomul introdus:");
            Console.WriteLine("");

            Complex[] lista = new Complex[degree + 1];
            for (int i = 0; i <= degree; ++i)
            {
                lista[i] = new Complex(coeffs[2 * i], coeffs[2 * i + 1]);
            }

            Polynom polynom = new Polynom(lista);

            return(polynom);
        }
예제 #30
0
        public void PolynomTest08()
        {
            //arrange
            int[]   test_array  = { 2, 0, 0, 0, -7 };
            int[]   test_array2 = { -113, 822, 3001, -455, -18 };
            int[]   exp_array   = { 115, -822, -3001, 455, 11 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);
            Polynom expected    = new Polynom(exp_array);
            //act
            Polynom result = p1 - p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #31
0
        public void PolynomTest10()
        {
            //arrange
            int[]   test_array  = { 0 };
            int[]   test_array2 = { 5, -1 };
            int[]   exp_array   = { -5, 1 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);
            Polynom expected    = new Polynom(exp_array);
            //act
            Polynom result = p1 - p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #32
0
        public void PolynomTest02()
        {
            //arrange
            int[]   test_array  = { 9, -5, 78, 19 };
            int[]   test_array2 = { -9, 0, 7 };
            int[]   exp_array   = { 0, -5, 85, 19 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);
            Polynom expected    = new Polynom(exp_array);
            //act
            Polynom result = p1 + p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #33
0
        public void PolynomTest11()
        {
            //arrange
            int[]   test_array  = { 17, -13, 5, -71 };
            int[]   test_array2 = { 5, -1, -8, -17, -12, -35 };
            int[]   exp_array   = { 12, -12, 13, -54, 12, 35 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);
            Polynom expected    = new Polynom(exp_array);
            //act
            Polynom result = p1 - p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #34
0
        public void PolynomTest03()
        {
            //arrange
            int[]   test_array  = { 49, -17, 145, 12, 2, 0, -8, 19, -15, -7 };
            int[]   test_array2 = { -91, -110, 77, 13, -13, -77, 17, 82, 301, -45 };
            int[]   exp_array   = { -42, -127, 222, 25, -11, -77, 9, 101, 286, -52 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);
            Polynom expected    = new Polynom(exp_array);
            //act
            Polynom result = p1 + p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #35
0
        public void PolynomTest04()
        {
            //arrange
            int[]   test_array  = { 49, -17, 145, 12, 2, 0, -8, 19, -15, -7 };
            int[]   test_array2 = { -13, -77, 17, 82, 301, -45 };
            int[]   exp_array   = { 36, -94, 162, 94, 303, -45, -8, 19, -15, -7 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);
            Polynom expected    = new Polynom(exp_array);
            //act
            Polynom result = p1 + p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #36
0
    public static List <Polynom[, ]> NOD(Polynom p11, Polynom p22)
    {
        int[] temp1 = new int[p11.coefficients.Length];
        int[] temp2 = new int[p22.coefficients.Length];
        p11.coefficients.CopyTo(temp1, 0);
        p22.coefficients.CopyTo(temp2, 0);
        Polynom p1 = new Polynom(temp1);
        Polynom p2 = new Polynom(temp2);
        KeyValuePair <Polynom, Polynom> p;

        Polynom[,] matrix;
        List <Polynom[, ]> polynoms = new List <Polynom[, ]>();

        if (p1.degree >= p2.degree)
        {
            p = p1 / p2;
            while (p.Value.degree > 0)
            {
                matrix = new Polynom[2, 2] {
                    { new Polynom(p.Key.coefficients), new Polynom(1) }, { new Polynom(1), new Polynom(0) }
                };
                polynoms.Add(matrix);
                p1 = p2;
                p2 = p.Value;
                p  = p1 / p2;
            }
            matrix = new Polynom[2, 2] {
                { new Polynom(p.Key.coefficients), new Polynom(1) }, { new Polynom(1), new Polynom(0) }
            };
            polynoms.Add(matrix);
        }
        else
        {
            p = p2 / p1;
            while (p.Value.degree > 0)
            {
                matrix = new Polynom[2, 2] {
                    { new Polynom(p.Key.coefficients), new Polynom(1) }, { new Polynom(1), new Polynom(0) }
                };
                polynoms.Add(matrix);
                p2 = p1;
                p1 = p.Value;
                p  = p2 / p1;
            }
        }
        polynoms.Reverse();
        return(polynoms);
    }
예제 #37
0
파일: Scheme.cs 프로젝트: sunshykin/SZDL
        private static Polynom[] GenerateCenteredVector(int centeringModulo, int length)
        {
            var result = new Polynom[length];

            for (int iterVect = 0; iterVect < length; iterVect++)
            {
                result[iterVect] = new Polynom(512);

                for (int iterPoly = 0; iterPoly < 512; iterPoly++)
                {
                    result[iterVect].Coefficients[iterPoly] = GenerateNumberInBoundaries(centeringModulo);
                }
            }

            return(result);
        }
예제 #38
0
        public void PolynomTest01()
        {
            //arrange
            int[]   test_array  = { 7, -3, -5 };
            int[]   test_array2 = { 9, 5 };
            int[]   exp         = { 63, 8, -60, -25 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);

            Polynom expected = new Polynom(exp);
            //act
            Polynom result = p1 * p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #39
0
        public void PolynomTest12()
        {
            //arrange
            int[]   test_array  = { 7, -3, -5, -9, 25, 17, 63, 32, -18, 219, 30, -1 };
            int[]   test_array2 = { 9, 5, 13, -15, -7, 5, 550, 1, 13, -52, 7 };
            int[]   exp         = { 63, 8, 31, -250, 111, 292, 4982, -1156, -2320, -4000, 14176, 12846, 32811, 14435, -8858, 117848, 15257, 3487, -11125, -40, 262, -7 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);

            Polynom expected = new Polynom(exp);
            //act
            Polynom result = p1 * p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #40
0
        public void PolynomTest13()
        {
            //arrange
            int[]   test_array  = { 9, 5, 1, -71, 13, -52, 7 };
            int[]   test_array2 = { 0 };
            int[]   exp         = { 0, 0, 0, 0, 0, 0, 0 };
            Polynom p1          = new Polynom(test_array);
            Polynom p2          = new Polynom(test_array2);

            Polynom expected = new Polynom(exp);
            //act
            Polynom result = p1 * p2;

            //assert
            Assert.IsTrue(expected == result);
        }
예제 #41
0
        public static void GetDiv(List <double> pol1, List <double> pol2, out string result, out string residue)
        {
            Polynom a = new Polynom();;
            Polynom b = new Polynom();

            a.SetA(pol1);
            b.SetA(pol2);

            Polynom res   = new Polynom();
            Polynom resid = new Polynom();

            Divide(a, b, out res, out resid);

            result  = Show(res);
            residue = Show(resid);
        }
예제 #42
0
 public override Polynom GetImplicitPolynomial()
 {
     if (implicitPolynomial == null)
     {
         PolynomVector w = zAxis ^ (location.ToVector() - PolynomVector.xyz);       // the distance of a point to the axis
         Polynom       l = zAxis * PolynomVector.xyz - zAxis * location.ToVector(); // the distance from location along the axis
         //(w*w)/(l*l)==(xAxis*xAxis)/(zAxis*zAxis) == tan(half opening angle)
         implicitPolynomial = (w * w) - ((xAxis * xAxis) / (zAxis * zAxis)) * (l * l);
         double   d1 = implicitPolynomial.Eval(PointAt(new GeoPoint2D(0.5, 0.5)));
         double   d2 = implicitPolynomial.Eval(PointAt(new GeoPoint2D(10, -10)));
         GeoPoint p  = PointAt(new GeoPoint2D(1, 0)) + GetNormal(new GeoPoint2D(1, 0)).Normalized; // a point with distance 1 from the cone
         double   d  = implicitPolynomial.Eval(p);                                                 // this should be 1
         implicitPolynomial = (1 / d) * implicitPolynomial;                                        // OK, this makes a good scaling (but it is not the distance)
     }
     return(implicitPolynomial);
 }
예제 #43
0
        static void Main(string[] args)
        {
            Function f1 = new SinFunc();

            f1.argumentFunction = new Argum();
            Function f2 = new CosFunc();

            f2.argumentFunction = new ExpFunc();
            f2.argumentFunction.argumentFunction = new Argum();
            Function f3 = new AddOper(f1, f2);

            Console.WriteLine(f1.ToString());
            Console.WriteLine(f2.ToString());
            Console.WriteLine(f3.ToString());
            Console.WriteLine("===========================");
            Console.WriteLine("Diff " + f2.ToString() + " = " + f2.Diff().ToString() + "\n");
            Console.WriteLine("===========================");
            Console.WriteLine("Value " + f2.ToString() + "=" + f2.Diff().ToString() + "\n");
            Console.WriteLine("===========================");
            string Path = "XMLoutput.xml";

            using (StreamWriter sw = new StreamWriter(Path, false, System.Text.Encoding.Default))
            {
                sw.WriteLine(f2.ToXML());
            }
            Dictionary <int, double> Coefficients = new Dictionary <int, double>();

            Coefficients.Add(0, 2);
            Coefficients.Add(1, 7);
            Function f4 = new Polynom(f2, Coefficients);

            Console.WriteLine(f4.ToString());
            Console.WriteLine("===========================");
            double val = f2.CalculateCalc(5);

            Console.WriteLine(f2.ToString() + "=" + val);

            string Path1 = "XMLoutput1.xml";

            using (StreamWriter sw = new StreamWriter(Path1, false, System.Text.Encoding.Default))
            {
                sw.WriteLine(f4.ToXML());
            }

            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
예제 #44
0
        public double FindRoot(Polynom polynom, double start, double end)
        {
            const double Eps = 0.000001;
            var fstart = polynom.Calculate(start);
            while (Math.Abs(start - end) > Eps)
            {
                var center = (start + end) / 2;
                var fcenter = polynom.Calculate(center);
                if (fstart * fcenter <= 0)
                {
                    end = center;
                }
                else
                {
                    start = center;
                    fstart = fcenter;
                }
            }

            return start;
        }
예제 #45
0
            public Lagrange_Polynom(double[,] X_FfromX)
            {
                Polynom[] l = new Polynom[X_FfromX.Length / 2];
                bool l_used;
                for (int i = 0; i < l.Length; i++)
                {
                    Polynom tempPoly;
                    double[] tempDoub = new double[2];
                    l_used = false;
                    for (int j = 0; j < l.Length; j++)
                    {
                        if (i != j)
                        {
                            tempDoub[0] = -1 * X_FfromX[0, j] / (X_FfromX[0, i] - X_FfromX[0, j]);
                            tempDoub[1] = 1 / (X_FfromX[0, i] - X_FfromX[0, j]);
                            if (l_used)
                            {
                                tempPoly = new Polynom(tempDoub, 2);
                                l[i] = l[i] * tempPoly;
                            }
                            else
                            {
                                l_used = true;
                                l[i] = new Polynom(tempDoub, 2);
                            }
                        }
                    }
                    l[i] = l[i] * X_FfromX[1, i];

                }
                Polynom result = l[0];
                for (int i = 1; i < l.Length; i++)
                {
                    result = result + l[i];
                }

                this.coef = result.COEF;
            }
예제 #46
0
 static void Main(string[] args)
 {
     int[] array1 = { 1, 2, 3, 4 };
     int[] array2 = { 1, 2, 3, 4 };
        // int[] array3 = { 1, 2, 3, 4 };
     Polynom p1 = new Polynom(array1,3);
     Polynom p2 = new Polynom(array2, 3);
     Polynom p3 = p1 + p2;
     Console.WriteLine("\n"+"P3=P1+P2");
     p3.Show();
     Console.WriteLine("\n" + "P1=");
     p1.Show();
     Console.WriteLine("\n" + "P2=");
     p2.Show();
     Polynom p4 = p1 - p2;
     Console.WriteLine("\n" + "P4=P1-P2");
     p4.Show();
     Console.WriteLine(Object.Equals(p1, p2));
     Console.WriteLine(p1.ToString());
     Polynom p5 = p1 * 5;
     p5.Show();
     Console.ReadKey();
 }
예제 #47
0
 public static Polynom operator -(Polynom a, Polynom b)
 {
     int max = Math.Max(a.coef.Length, b.coef.Length);
     Polynom result = new Polynom(max);
     for (int i = 0; i < a.coef.Length && i < b.coef.Length; i++)
     {
         result.coef[i] = a.coef[i] - b.coef[i];
     }
     return result;
 }
예제 #48
0
 public static Polynom operator -(Polynom a, double b)
 {
     Polynom result = new Polynom(a.coef.Length);
     result = result + a;
     result.coef[0] -= b;
     return result;
 }
예제 #49
0
 public static Polynom operator /(Polynom a, double b)
 {
     Polynom result = new Polynom(a.coef.Length);
     result = result + a;
     for (int i = 0; i < result.coef.Length; i++)
         result.coef[i] /= b;
     return result;
 }
예제 #50
0
 public void EditCoef(int coefficient, double data)
 {
     if (coefficient > coef.Length)
     {
         Polynom a = new Polynom(coefficient);
         a = a + this;
         a.EditCoef(coefficient, data);
         this.coef = a.coef;
     }
     else
     this.coef[coefficient] = data;
 }
 private static Polynom MultiplyGeneratorPolynomByLeadterm(Polynom genPolynom, PolynomItem leadTerm, int lowerExponentBy)
 {
     var resultPolynom = new Polynom();
     foreach (var polItemRes in genPolynom.PolyItems.Select(polItemBase => new PolynomItem
     {
         Coefficient = (polItemBase.Coefficient + leadTerm.Coefficient)%255,
         Exponent = polItemBase.Exponent - lowerExponentBy
     }))
     {
         resultPolynom.PolyItems.Add(polItemRes);
     }
     return resultPolynom;
 }
예제 #52
0
 private Polynom ConvertToDecNotation(Polynom poly)
 {
     var newPoly = new Polynom();
     for (var i = 0; i < poly.PolyItems.Count; i++)
         newPoly.PolyItems.Add(new PolynomItem(this.GetIntValFromAlphaExp(poly.PolyItems[i].Coefficient), poly.PolyItems[i].Exponent));
     return newPoly;
 }
 private Polynom MultiplyAlphaPolynoms(Polynom polynomBase, Polynom polynomMultiplier)
 {
     var resultPolynom = new Polynom();
     foreach (var polItemRes in polynomMultiplier.PolyItems.SelectMany(polItemBase => polynomBase.PolyItems.Select(polItemMulti => new PolynomItem
     {
         Coefficient = ShrinkAlphaExp(polItemBase.Coefficient + polItemMulti.Coefficient),
         Exponent = (polItemBase.Exponent + polItemMulti.Exponent)
     })))
     {
         resultPolynom.PolyItems.Add(polItemRes);
     }
     var exponentsToGlue = resultPolynom.PolyItems.GroupBy(x => x.Exponent).Where(x => x.Count() > 1).Select(x => x.First().Exponent);
     var gluedPolynoms = new List<PolynomItem>();
     foreach (var exponent in exponentsToGlue)
     {
         var polynomFixed = new PolynomItem {Exponent = exponent};
         var coefficient = resultPolynom.PolyItems.Where(x => x.Exponent == exponent).Aggregate(0, (current, polynomOld) => current ^ GetIntValFromAlphaExp(polynomOld.Coefficient));
         polynomFixed.Coefficient = GetAlphaExpFromIntVal(coefficient);
         gluedPolynoms.Add(polynomFixed);
     }
     resultPolynom.PolyItems.RemoveAll(x => exponentsToGlue.Contains(x.Exponent));
     resultPolynom.PolyItems.AddRange(gluedPolynoms);
     resultPolynom.PolyItems = resultPolynom.PolyItems.OrderByDescending(x => x.Exponent).ToList();
     return resultPolynom;
 }
예제 #54
0
        private Polynom CalculateGeneratorPolynom(int numEccWords)
        {
            var generatorPolynom = new Polynom();
            generatorPolynom.PolyItems.AddRange(new[]{
                new PolynomItem(0,1),
                new PolynomItem(0,0)
            });
            for (var i = 1; i <= numEccWords - 1; i++)
            {
                var multiplierPolynom = new Polynom();
                multiplierPolynom.PolyItems.AddRange(new[]{
                   new PolynomItem(0,1),
                new PolynomItem(i,0)
                });

                generatorPolynom = this.MultiplyAlphaPolynoms(generatorPolynom, multiplierPolynom);
            }

            return generatorPolynom;
        }
예제 #55
0
 private Polynom CalculateMessagePolynom(string bitString)
 {
     var messagePol = new Polynom();
     for (var i = bitString.Length / 8 - 1; i >= 0; i--)
     {
         messagePol.PolyItems.Add(new PolynomItem(this.BinToDec(bitString.Substring(0, 8)), i));
         bitString = bitString.Remove(0, 8);
     }
     return messagePol;
 }
예제 #56
0
        private Polynom XORPolynoms(Polynom messagePolynom, Polynom resPolynom)
        {
            var resultPolynom = new Polynom();
            Polynom longPoly, shortPoly;
            if (messagePolynom.PolyItems.Count >= resPolynom.PolyItems.Count)
            {
                longPoly = messagePolynom;
                shortPoly = resPolynom;
            }
            else
            {
                longPoly = resPolynom;
                shortPoly = messagePolynom;
            }

            for (var i = 0; i < longPoly.PolyItems.Count; i++)
            {
                var polItemRes = new PolynomItem
                (

                        longPoly.PolyItems[i].Coefficient ^
                        (shortPoly.PolyItems.Count > i ? shortPoly.PolyItems[i].Coefficient : 0),
                    messagePolynom.PolyItems[0].Exponent - i
                );
                resultPolynom.PolyItems.Add(polItemRes);
            }
            resultPolynom.PolyItems.RemoveAt(0);
            return resultPolynom;
        }
예제 #57
0
        private Polynom MultiplyGeneratorPolynomByLeadterm(Polynom genPolynom, PolynomItem leadTerm, int lowerExponentBy)
        {
            var resultPolynom = new Polynom();
            foreach (var polItemBase in genPolynom.PolyItems)
            {
                var polItemRes = new PolynomItem(

                    (polItemBase.Coefficient + leadTerm.Coefficient) % 255,
                    polItemBase.Exponent - lowerExponentBy
                );
                resultPolynom.PolyItems.Add(polItemRes);
            }
            return resultPolynom;
        }
예제 #58
0
 private Polynom MultiplyAlphaPolynoms(Polynom polynomBase, Polynom polynomMultiplier)
 {
     var resultPolynom = new Polynom();
     foreach (var polItemBase in polynomMultiplier.PolyItems)
     {
         foreach (var polItemMulti in polynomBase.PolyItems)
         {
             var polItemRes = new PolynomItem
             (
                 ShrinkAlphaExp(polItemBase.Coefficient + polItemMulti.Coefficient),
                 (polItemBase.Exponent + polItemMulti.Exponent)
             );
             resultPolynom.PolyItems.Add(polItemRes);
         }
     }
     var exponentsToGlue = resultPolynom.PolyItems.GroupBy(x => x.Exponent).Where(x => x.Count() > 1).Select(x => x.First().Exponent);
     var gluedPolynoms = new List<PolynomItem>();
     var toGlue = exponentsToGlue as IList<int> ?? exponentsToGlue.ToList();
     foreach (var exponent in toGlue)
     {
         var coefficient = resultPolynom.PolyItems.Where(x => x.Exponent == exponent).Aggregate(0, (current, polynomOld)
             => current ^ this.GetIntValFromAlphaExp(polynomOld.Coefficient));
         var polynomFixed = new PolynomItem(this.GetAlphaExpFromIntVal(coefficient), exponent);
         gluedPolynoms.Add(polynomFixed);
     }
     resultPolynom.PolyItems.RemoveAll(x => toGlue.Contains(x.Exponent));
     resultPolynom.PolyItems.AddRange(gluedPolynoms);
     resultPolynom.PolyItems = resultPolynom.PolyItems.OrderByDescending(x => x.Exponent).ToList();
     return resultPolynom;
 }
        private Polynom CalculateGeneratorPolynom(int numEccWords)
        {
            var generatorPolynom = new Polynom();
            generatorPolynom.PolyItems.AddRange(new []{
                new PolynomItem { Coefficient = 0, Exponent = 1},
                new PolynomItem { Coefficient = 0, Exponent = 0}
            });
            for (var i = 1; i <= numEccWords - 1; i++)
            {
                var multiplierPolynom = new Polynom();
                multiplierPolynom.PolyItems.AddRange(new []{
                    new PolynomItem { Coefficient = 0, Exponent = 1},
                    new PolynomItem { Coefficient = i, Exponent = 0}
                });

                generatorPolynom = MultiplyAlphaPolynoms(generatorPolynom, multiplierPolynom);
            }

            return generatorPolynom;
        }
예제 #60
0
 private Polynom ConvertToAlphaNotation(Polynom poly)
 {
     var newPoly = new Polynom();
     for (var i = 0; i < poly.PolyItems.Count; i++)
         newPoly.PolyItems.Add(
             new PolynomItem(
                 (poly.PolyItems[i].Coefficient != 0
                     ? this.GetAlphaExpFromIntVal(poly.PolyItems[i].Coefficient)
                     : 0), poly.PolyItems[i].Exponent));
     return newPoly;
 }