Пример #1
0
        static ComplexL MultiplyOf(ComplexL a, ComplexL b)
        {
            ComplexL res = new ComplexL(a);

            res.Multiply(b);
            return(res);
        }
Пример #2
0
        static ComplexL SumOf(ComplexL a, ComplexL b)
        {
            ComplexL res = new ComplexL(a);

            res.Add(b);
            return(res);
        }
Пример #3
0
        private void Multiply(ComplexL c)
        {
            var t = _real;

            _real    = _real * c._real - _imagine * c._imagine;
            _imagine = t * c._imagine + _imagine * c._real;
        }
Пример #4
0
        static ComplexL DivideOf(ComplexL a, ComplexL b)
        {
            ComplexL res = new ComplexL(a);

            res.Divide(b);
            return(res);
        }
Пример #5
0
        static ComplexL SubtractOf(ComplexL a, ComplexL b)
        {
            ComplexL res = new ComplexL(a);

            res.Subtract(b);
            return(res);
        }
Пример #6
0
        private void Divide(ComplexL c)
        {
            if (Math.Abs(c.Abs) < double.Epsilon)
            {
                DivideByZeroEvent?.Invoke(this, new ComplexEventArgs("Divide by zero", this, c));
                return;
            }
            ComplexL t = new ComplexL(this);

            t.Multiply(c.Conjugate());
            t.Divide(c.Abs);
        }
Пример #7
0
        public T Abs()
        {
            var res = new T();

            res = _vec.Aggregate(res, (current, c) => current + (dynamic)c * c);
            res = res switch
            {
                ComplexL c => (dynamic)c.Root(2)[0],
                _ => (T)Math.Sqrt((dynamic)res)
            };

            return(res);
        }
Пример #8
0
        static void Main(string[] args)
        {
            if (true)
            {
                var c = new ComplexL(-1, 0);
                c.DivideByZeroEvent += PrintEvent;
                c.DivideByZeroEvent += PrintEventWithArgs;

                var c2 = new ComplexL(0, 0);
                // Console.WriteLine($"c2 arg = {c2.Arg}");
                // Console.WriteLine(c / c2);
                foreach (var complexL in c.Root(2))
                {
                    Console.WriteLine(complexL);
                }
            }

            // int[] a = {1, 2, 3};
            // var b = new[] {1, 2, 3};
            // var v = new VectorL<int>(new int[]{1234, 2});

            if (!true)
            {
                // var doubleArr_1 = new double[4] { 3.0, 2.0, 1.0, 1.0 };
                // var doubleArr_2 = new double[4] { 3.0, 3.0, 1.0, 2.0 };
                // var doubleArr_3 = new double[4] { 1.0, 2.0, 1.0, 2.0 };
                var basis = new[]
                {
                    new VectorL <double>(3.0, 2.0, 1.0, 1.0),
                    new VectorL <double>(3.0, 3.0, 1.0, 2.0),
                    new VectorL <double>(1.0, 2.0, 1.0, 2.0)
                };
                foreach (var v in VectorL <double> .Orthogonality(basis))
                {
                    Console.WriteLine(v);
                }
            }

            if (!true)
            {
                var basis = new[]
                {
                    new VectorL <ComplexL>(ComplexL.One, ComplexL.Zero, ComplexL.Zero),
                    new VectorL <ComplexL>(ComplexL.Zero, ComplexL.One, ComplexL.Zero),
                    new VectorL <ComplexL>(ComplexL.Zero, ComplexL.Zero, ComplexL.One),
                };

                var newBasis = VectorL <ComplexL> .Orthogonality(basis);

                newBasis.ForEach(Console.WriteLine);
                Console.WriteLine($"Vec length = {newBasis[0].Abs()}");
            }

            if (!true)
            {
                VectorL <int> a = new VectorL <int>(3, 2, 2), b = new VectorL <int>(3, 2, 2);
                Console.WriteLine(a == b);
            }

            if (false)
            {
                var v = new VectorL <int>();
                Console.WriteLine(v);
            }

            // var v1 = new VectorL<ComplexL>(ComplexL.One, ComplexL.Zero, ComplexL.Zero);
            // Console.WriteLine(v1.Abs());
        }
Пример #9
0
 private void Subtract(ComplexL c)
 {
     _real    -= c._real;
     _imagine -= c._real;
 }
Пример #10
0
 private void Add(ComplexL c)
 {
     _real    += c._real;
     _imagine += c._imagine;
 }
Пример #11
0
 public ComplexL(ComplexL c)
 {
     _real             = c._real;
     _imagine          = c._imagine;
     DivideByZeroEvent = c.DivideByZeroEvent;
 }
Пример #12
0
 public ComplexEventArgs(string message, ComplexL first, ComplexL second)
 {
     Message = message;
     First   = first;
     Second  = second;
 }
Пример #13
0
 public ComplexEventArgs(string msg, ComplexL first)
 {
     Message = msg;
     First   = first;
 }