Ejemplo n.º 1
0
        public void Test_subtract_numb()
        {
            int a = 1;

            testClass = testClass - a;
            Assert.AreEqual(testClass.Re, -1, "неверный результат вычитания числа");
        }
Ejemplo n.º 2
0
        public void Test_sum_numb()
        {
            int a = 1;

            testClass = testClass + a;
            Assert.AreEqual(testClass.Re, 1, "неверный результат сложения c числом");
        }
Ejemplo n.º 3
0
        public void Pow_WithoutRe()
        {
            var actual   = calc.Pow(new ComplexNum(0, -7), 5);
            var expected = new ComplexNum(0, -16807);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 4
0
    private ComplexNum GCDComplex(ComplexNum a, ComplexNum b)
    {
        //assume a.mag() > b.mag()
        //a/b = x+yi
        //round x and y to closest ints that gives you q
        //r = a-b*q
        //repeat until r=0

        /* ComplexNum r = new ComplexNum(1, 1);
         * if (a.mag() > b.mag())
         * {
         *
         *   ComplexNum c = a / b;
         *   ComplexNum q = new ComplexNum();
         *   q.r = Math.Round(c.r);
         *   q.i = Math.Round(c.i);
         *   r = a - (b * q);
         *   if (r.r == 0 && r.i == 0)
         *   {
         *       return q;
         *   }
         *   else
         *   {
         *       return GCDComplex(r, b);
         *   }
         * }
         * else if()
         * {
         *
         * }*/
        return(null);
    }
Ejemplo n.º 5
0
        public void Prod_Negative()
        {
            var actual   = calc.Prod(new ComplexNum(-5, -5), new ComplexNum(-1, -6));
            var expected = new ComplexNum(-25, 35);

            Assert.AreEqual(expected, actual);
        }
 private void plusButton_Click(object sender, RoutedEventArgs e)
 {
     num1 = new ComplexNum(Convert.ToDouble(realPartInput.Text), Convert.ToDouble(imaginaryPartInput.Text));
     znak = (sender as Button).Content.ToString()[0];
     imaginaryPartInput.Clear();
     realPartInput.Clear();
 }
Ejemplo n.º 7
0
        public void Equals()
        {
            var num    = new ComplexNum(4, 6);
            var actual = num.Equals(new ComplexNum(4, 6));

            Assert.AreEqual(true, actual);
        }
Ejemplo n.º 8
0
        public void Sum()
        {
            var actual   = calc.Sum(new ComplexNum(4, -9), new ComplexNum(-5, 12));
            var expected = new ComplexNum(-1, 3);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
        public void Dif()
        {
            var actual   = calc.Dif(new ComplexNum(9, 10), new ComplexNum(-9, 1));
            var expected = new ComplexNum(18, 9);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        private void But_Click(object sender, EventArgs e)
        {
            if (nNatural.Text.Length == 0)
            {
                MessageBox.Show("Campo n vacio", "◄ AVISO ►", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            else
            {
                try
                {
                    N1   = new ComplexNum(Convert.ToDouble(NumR1.Text), Convert.ToDouble(NumU1.Text));
                    N2   = new ComplexNum(Convert.ToDouble(NumR2.Text), Convert.ToDouble(NumU2.Text));
                    _Sum = N1.Sum(N2.getReal(), N2.getUnreal());
                    _Res = N1.Res(N2.getReal(), N2.getUnreal());
                    _Mul = N1.Mul(N2.getReal(), N2.getUnreal());
                    _Div = N1.Div(N2.getReal(), N2.getUnreal());
                    _Pow = N2.Pow(Convert.ToInt32(nPow.Text));
                    //Console.WriteLine("--------------");
                    //Console.WriteLine("r: " + _Pow.getr() + "  teta:" + _Pow.getTeta() * 180 / Math.PI);
                    //Console.WriteLine("--------------");

                    Sum.Text = _Sum.getReal() + ((_Sum.getUnreal() > 0) ? " + " : " - ") + Math.Abs(_Sum.getUnreal()) + " i";
                    Div.Text = (_Div == null) ? "Math Error" : _Div.getReal() + ((_Div.getUnreal() > 0) ? " + " : " - ") + Math.Abs(_Div.getUnreal()) + " i";
                    Res.Text = _Res.getReal() + ((_Res.getUnreal() > 0) ? " + " : " - ") + Math.Abs(_Res.getUnreal()) + " i";
                    Mul.Text = _Mul.getReal() + ((_Mul.getUnreal() > 0) ? " + " : " - ") + Math.Abs(_Mul.getUnreal()) + " i";
                    Pow.Text = _Pow.Printable();
                    Console.WriteLine(_Pow.getReal() + "====" + _Pow.getUnreal());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
Ejemplo n.º 11
0
        public static Vector3 positionMap(Vector3 whereImShootingFrom, Vector3 whatDirectionImShooting, float t)
        {
            switch (currentGeometry)
            {
            case "Nil":
                Vector3 velocityAtOrigin = NilMultiply(-1 * whereImShootingFrom, whereImShootingFrom + whatDirectionImShooting);
                float   r      = (float)Math.Pow(Mathf.Pow(velocityAtOrigin.x, 2f) + Mathf.Pow(velocityAtOrigin.z, 2f), 0.5f);
                float   varphi = (float)Mathf.Atan2(velocityAtOrigin.z, velocityAtOrigin.x);
                float   gamma  = velocityAtOrigin.y;
                return(NilMultiply(
                           whereImShootingFrom,
                           nilGeodesicEqn(r, varphi, gamma, t)
                           ));

            case "Half-Space":
                float      phi      = Mathf.Atan2(whatDirectionImShooting.z, whatDirectionImShooting.x);
                float      theta    = Mathf.Acos(whatDirectionImShooting.y);
                ComplexNum geodesic = FLTGamma(
                    theta, t
                    );
                Vector3 positionMapped = new Vector3(
                    Mathf.Cos(phi) * geodesic.r * whereImShootingFrom.y + whereImShootingFrom.x,
                    geodesic.i * whereImShootingFrom.y,
                    Mathf.Sin(phi) * geodesic.r * whereImShootingFrom.y + whereImShootingFrom.z
                    );

                return(positionMapped);

            default:
                return(whereImShootingFrom + whatDirectionImShooting * t);
            }
        }
Ejemplo n.º 12
0
Archivo: 1_5.cs Proyecto: wztch/Tasks
        public void Main1_5()
        {
            string input1,
                   input2;
            int        n    = 0;
            ComplexNum num1 = new ComplexNum();
            ComplexNum num2 = new ComplexNum();

            for (int i = 1; i < 3; i++)
            {
                Console.WriteLine("Enter {0} complex number:", i);
                input1 = Console.ReadLine();
                Console.SetCursorPosition(input1.Length + 1, 2 + n);
                Console.Write("+ ");
                input2 = Console.ReadLine();
                Console.SetCursorPosition(input1.Length + 3 + input2.Length, 2 + n);
                Console.WriteLine("i");

                if (n == 0)
                {
                    num1 = new ComplexNum(Convert.ToDouble(input1), Convert.ToDouble(input2));
                    n   += 2;
                }
                else
                {
                    num2 = new ComplexNum(Convert.ToDouble(input1), Convert.ToDouble(input2));
                }
            }

            ComplexNum num3 = new ComplexNum();

            num3 = num1 * num2;
            num3 = num1 / num2;
        }
Ejemplo n.º 13
0
        public void Prod_PosAndNeg()
        {
            var actual   = calc.Prod(new ComplexNum(5, -6), new ComplexNum(5, -6));
            var expected = new ComplexNum(-11, -60);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        public void Div_ReByRe()
        {
            var actual   = calc.Div(new ComplexNum(20, 0), new ComplexNum(5, 0));
            var expected = new ComplexNum(4, 0);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 15
0
        public void Pow_ReAndIm()
        {
            var actual   = calc.Pow(new ComplexNum(5, -6), 2);
            var expected = new ComplexNum(-11, -60);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 16
0
        public void Div_WithoutRe()
        {
            var actual   = calc.Div(new ComplexNum(12, 4), new ComplexNum(0, 4));
            var expected = new ComplexNum(1, -3);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 17
0
        public void Div_Wholly()
        {
            var actual   = calc.Div(new ComplexNum(16, 8), new ComplexNum(8, 4));
            var expected = new ComplexNum(2, 0);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 18
0
        public void Div_WithoutIm()
        {
            var actual   = calc.Div(new ComplexNum(18, 10), new ComplexNum(2, 0));
            var expected = new ComplexNum(9, 5);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 19
0
        public void Div_ReAndIm()
        {
            var actual   = calc.Div(new ComplexNum(-2, 1), new ComplexNum(1, -1));
            var expected = new ComplexNum(-1.5, -0.5);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 20
0
        public void Pow_WithoutIm()
        {
            var actual   = calc.Pow(new ComplexNum(3, 0), 0);
            var expected = new ComplexNum(1, 0);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 21
0
        public void NotEquals()
        {
            var num    = new ComplexNum(-4, 6);
            var actual = num.Equals(new ComplexNum(4, -6));

            Assert.AreEqual(false, actual);
        }
Ejemplo n.º 22
0
        public void Test_sum()
        {
            ComplexNum temp = new ComplexNum(1, 1);

            testClass = testClass + temp;
            Assert.AreEqual(testClass.ToString(), temp.ToString(), "неверный результат сложения");
        }
Ejemplo n.º 23
0
Archivo: 1_5.cs Proyecto: wztch/Tasks
    public static ComplexNum operator /(ComplexNum first, ComplexNum second)
    {
        ComplexNum result = new ComplexNum(first.real / second.real, first.imaginary / second.imaginary);

        Console.WriteLine("Result of division: {0} + {1}i", result.real, result.imaginary);
        return(result);
    }
Ejemplo n.º 24
0
        public void Prod_Positive()
        {
            var actual   = calc.Prod(new ComplexNum(10, 9), new ComplexNum(7, 15));
            var expected = new ComplexNum(-65, 213);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 25
0
        public void Test_subtract()
        {
            ComplexNum temp   = new ComplexNum(1, 1);
            String     answer = "-1 + i-1";

            testClass = testClass - temp;
            Assert.AreEqual(testClass.ToString(), answer, "неверный результат разности");
        }
Ejemplo n.º 26
0
        public void Test_multiplication()
        {
            ComplexNum temp = new ComplexNum(2, 2);

            testClass = new ComplexNum(2, 2);
            String answer = "0 + i8";

            testClass = testClass * temp;
            Assert.AreEqual(testClass.ToString(), answer, "неверный результат произведения");
        }
Ejemplo n.º 27
0
            static void DZ3_1()
            {
                ComplexNum a = new ComplexNum(1.1, 5.4);
                ComplexNum b = new ComplexNum(3.2, 3.5);

                ComplexNum sum = a + b;
                ComplexNum ext = a - b;

                Console.WriteLine($"Дано\nКомплексное число a({ a.Re }; { a.Im }); \nКомплексное число b({ b.Re }; { b.Im }).");
                Console.WriteLine($"a - b будет  ({ ext.Re }; { ext.Im }), \na + b будет ({ sum.Re }, { sum.Im }).");
            }
Ejemplo n.º 28
0
        public Roots(List <string> The_Roots, ComplexNum Num, List <ComplexNum> Roots_Num)
        {
            InitializeComponent();
            foreach (var item in The_Roots)
            {
                RootsArea.Text += item + Environment.NewLine;
            }

            RootsArea.Text += Environment.NewLine + "Pow: " + Num.Printable();
            this.Roots_Num  = Roots_Num;
            _Po             = Num;
        }
Ejemplo n.º 29
0
        private static ComplexNum FLTGamma(float theta, float time)
        {
            ComplexNum numerator = new ComplexNum(
                Mathf.Exp(time) * Mathf.Cos(theta / 2),
                Mathf.Sin(theta / 2)
                );
            ComplexNum denominator = new ComplexNum(
                Mathf.Exp(time) * Mathf.Sin(theta / 2),
                -1 * Mathf.Cos(theta / 2)
                );

            return(numerator / denominator);
        }
Ejemplo n.º 30
0
    private void drawFordSpheres(ComplexNum a, ComplexNum b)
    {
        ComplexNum coordinates = a / b; //Check / Funciton
        GameObject sphere      = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        float      radius      = 1.0f / (2.0f * b.mag() * b.mag());

        sphere.transform.position = new Vector3(coordinates.r, radius, coordinates.i);
        // sphere.transform.lossyScale = new Vector3();
        //add collider
        // sphere.AddComponent()
        //      SphereCollider sc = gameObject.AddComponent(typeof(SphereCollider)) as SphereCollider
        // sphere.collider.radius = 1.0f / (2.0f * b.mag() * b.mag());// Check the mag function
    }