예제 #1
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);
        }
예제 #2
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());
        }