Exemplo n.º 1
0
        public static GaPoTNumMultivector ComplexEigenPairToBivector(Complex eigenValue, Vector eigenVector)
        {
            var realValue = eigenValue.Real;
            var imagValue = eigenValue.Imaginary;

            var realVector = new GaPoTNumVector(eigenVector.Select(c => c.Real));
            var imagVector = new GaPoTNumVector(eigenVector.Select(c => c.Imaginary));

            var scalar = realValue * realValue + imagValue * imagValue;

            var angle = Math.Atan2(imagValue, realValue);

            Console.WriteLine($"Eigen value real part: {realValue.ToString("G").GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            Console.WriteLine($"Eigen value imag part: {imagValue.ToString("G").GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            Console.WriteLine($"Eigen value length: {scalar.ToString("G").GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            Console.WriteLine($"Eigen value angle: {angle.RadiansToDegrees().ToString("G").GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            Console.WriteLine("Eigen vector real part:");
            Console.WriteLine(realVector.TermsToLaTeX().GetLaTeXDisplayEquation());
            Console.WriteLine();

            Console.WriteLine("Eigen vector imag part:");
            Console.WriteLine(imagVector.TermsToLaTeX().GetLaTeXDisplayEquation());
            Console.WriteLine();


            var blade = realVector.Op(imagVector);

            Console.WriteLine("Blade:");
            Console.WriteLine(blade.ToLaTeXEquationsArray("B", @"\mu"));
            Console.WriteLine();

            var rotor = GaPoTNumMultivector.CreateSimpleRotor(angle, blade);

            Console.WriteLine("Final rotor:");
            Console.WriteLine(rotor.ToLaTeXEquationsArray("R", @"\mu"));
            Console.WriteLine();

            Console.WriteLine($"Is simple rotor? {rotor.IsSimpleRotor()}");
            Console.WriteLine();

            Console.WriteLine();

            return(rotor);
        }
Exemplo n.º 2
0
        public static void Execute3()
        {
            var bitsCount = 4;

            //var mv = GaPoTNumMultivector.CreateZero().AddTerms(
            //    Enumerable.Range(0, 1 << bitsCount).Select(id => new GaPoTNumMultivectorTerm(id, 1))
            //);

            var mv = GaPoTNumMultivector
                     .CreateZero()
                     .AddTerm(3, 1)
                     .AddTerm(5, 2)
                     .AddTerm(0, -2);

            Console.WriteLine(mv.ToText());
        }
        public static void Execute()
        {
            var n = 3;

            var fbdFrame = GaPoTNumFrame.CreateFbdFrame(n);

            var m1 = fbdFrame.GetMatrix(n - 1).GetLaTeXArray();
            var m2 = fbdFrame.GetInnerProductsMatrix().GetLaTeXArray();
            var m3 = fbdFrame.GetInnerAnglesInDegreesMatrix().GetLaTeXArray();

            Console.WriteLine("FBD Frame Matrix:");
            Console.WriteLine(m1);
            Console.WriteLine();

            Console.WriteLine("FBD Frame Inner Products Matrix:");
            Console.WriteLine(m2);
            Console.WriteLine();

            Console.WriteLine("FBD Frame Inner Angles Matrix:");
            Console.WriteLine(m3);
            Console.WriteLine();

            //return;

            var sourceFrame = GaPoTNumFrame.CreateBasisFrame(n);

            var uPseudoScalar = GaPoTNumMultivector
                                .CreateZero()
                                .SetTerm((1 << n) - 1, 1.0d);

            for (var refVectorIndex = 0; refVectorIndex < n; refVectorIndex++)
            {
                Console.Write(@"\section{Reference vector: $\mu_" + (refVectorIndex + 1) + "$}");
                Console.WriteLine();

                var kirchhoffFrameBase = GaPoTNumFrame.CreateEmptyFrame();

                var refVector = sourceFrame[refVectorIndex];
                for (var i = 0; i < n; i++)
                {
                    if (i == refVectorIndex)
                    {
                        continue;
                    }

                    kirchhoffFrameBase.AppendVector(sourceFrame[i] - refVector);
                }

                var kirchhoffFramesList =
                    kirchhoffFrameBase.GetFramePermutations();

                var j = 1;
                foreach (var kirchhoffFrame in kirchhoffFramesList)
                {
                    Console.Write(@"\subsection{Kirchhoff Frame Permutation " + j + "}");
                    Console.WriteLine();

                    var targetFrame = kirchhoffFrame.GetOrthogonalFrame(true);

                    targetFrame.AppendVector(
                        -GaPoTNumUtils
                        .OuterProduct(targetFrame)
                        .Gp(uPseudoScalar.CliffordConjugate())
                        .GetVectorPart()
                        );

                    Debug.Assert(
                        targetFrame.IsOrthonormal()
                        );

                    Debug.Assert(
                        sourceFrame.HasSameHandedness(targetFrame)
                        );

                    DisplayFrames(
                        sourceFrame,
                        kirchhoffFrame,
                        targetFrame
                        );

                    j++;
                }
            }
        }
Exemplo n.º 4
0
 public static GaPoTNumMultivector CreateBasisBlade(int idsPattern)
 {
     return(GaPoTNumMultivector.CreateZero().AddTerm(idsPattern, 1.0d));
 }
Exemplo n.º 5
0
        public static void Execute()
        {
            var refVectorIndex = 0;

            for (var n = 3; n <= 8; n++)
            {
                var uFrame =
                    GaPoTNumFrame.CreateBasisFrame(n);

                var uPseudoScalar =
                    GaPoTNumMultivector
                    .CreateZero()
                    .SetTerm((1 << n) - 1, 1.0d);

                var eFrame =
                    GaPoTNumFrame.CreateKirchhoffFrame(n, refVectorIndex);

                var pFrame =
                    uFrame.GetProjectionOnFrame(eFrame);

                var fbdFrame = GaPoTNumFrame.CreateFbdFrame(n);

                var rotorsSequence = GaPoTNumRotorsSequence.CreateFromFrames(
                    n,
                    pFrame,
                    fbdFrame
                    );


                //var pFrame1 = pFrame
                //    .GetSubFrame(0, n - 1)
                //    .PrependVector(GaPoTNumVector.CreateAutoVector(n))
                //    .GetOrthogonalFrame(true);

                //var fbdFrame1 = fbdFrame
                //    .GetSubFrame(0, n - 1)
                //    .PrependVector(GaPoTNumVector.CreateAutoVector(n))
                //    .GetOrthogonalFrame(true);

                //var rs = GaPoTNumRotorsSequence.Create(
                //    pFrame1.GetRotorsToFrame(fbdFrame1)
                //);

                var pFrame2 = rotorsSequence.Rotate(pFrame);

                Console.Write(@"\section{Dimensions: " + n + "}");
                Console.WriteLine();

                Console.Write(@"\subsection{FBD Frame:}");
                Console.WriteLine();

                DisplayFrame(fbdFrame);

                Console.Write(@"\subsection{Projected Frame:}");
                Console.WriteLine();

                DisplayFrame(pFrame);

                Console.Write(@"\subsection{Rotated Projected Frame:}");
                Console.WriteLine();

                DisplayFrame(pFrame2);

                Console.WriteLine("Rotors Sequence:");

                for (var i = 0; i < rotorsSequence.Count; i++)
                {
                    var rotorEquation =
                        rotorsSequence[i].ToLaTeXEquationsArray(
                            $"R_{{{i + 1}}}",
                            @"\mu"
                            );

                    Console.WriteLine(rotorEquation);
                    Console.WriteLine();
                }
            }
        }
Exemplo n.º 6
0
        public static void Execute(int n)
        {
            var uFrame =
                GaPoTNumFrame.CreateBasisFrame(n);

            var cFrame =
                GaPoTNumFrame.CreateGramSchmidtFrame(n, 0);

            var rs1 =
                GaPoTNumRotorsSequence.CreateFromOrthonormalFrames(cFrame, uFrame);

            var rotationMatrix = (Matrix)Matrix.Build.DenseOfArray(
                rs1.GetFinalMatrix(n).ToComplexArray()
                );

            var cFrameMatrix = (Matrix)Matrix.Build.DenseOfArray(
                cFrame.GetMatrix().ToComplexArray()
                );

            //Make sure the rotation matrix is correct
            var m = rotationMatrix.Multiply(cFrameMatrix);

            var finalRotor = rs1.GetFinalRotor();

            Console.WriteLine("Rotation matrix:");
            Console.WriteLine(rotationMatrix);
            Console.WriteLine();

            Console.WriteLine("Final rotor:");
            Console.WriteLine(finalRotor.ToLaTeXEquationsArray("R", @"\mu"));
            Console.WriteLine();

            Console.WriteLine("Rotated cFrame using matrix:");
            Console.WriteLine("MatrixForm[" + m + "]");
            Console.WriteLine();

            rotationMatrix.EigenDecomposition(out var eigenValuesExpr, out var eigenVectorsExpr);

            Console.WriteLine("Eigen values:");
            foreach (var value in eigenValuesExpr)
            {
                Console.WriteLine(value);
            }
            Console.WriteLine();

            Console.WriteLine("Eigen vectors:");
            foreach (var vector in eigenVectorsExpr)
            {
                Console.WriteLine(vector);
            }
            Console.WriteLine();


            var eigenRotorsArray = new GaPoTNumMultivector[n];

            for (var i = 0; i < n; i++)
            {
                eigenRotorsArray[i] = ComplexEigenPairToBivector(
                    eigenValuesExpr[i],
                    eigenVectorsExpr[i]
                    );
            }

            //Make sure the blades of these rotors are eigen blades of the rotation matrix
            for (var i = 0; i < n; i++)
            {
                var(angleExpr, blade) =
                    eigenRotorsArray[i].GetSimpleRotorAngleBlade();

                var bladeDiff = (rs1.Rotate(blade) - blade).Round(7);

                Console.WriteLine("Angle:");
                Console.WriteLine(angleExpr.ToString("G").GetLaTeXDisplayEquation());
                Console.WriteLine();

                Console.WriteLine("Blade:");
                Console.WriteLine(blade.ToLaTeXEquationsArray("b_1", @"\mu"));
                Console.WriteLine();

                Console.WriteLine("Rotated Blade - Blade:");
                Console.WriteLine(bladeDiff.ToLaTeXEquationsArray("b_1", @"\mu"));
                Console.WriteLine();
            }

            var diff =
                (eigenRotorsArray[0].Gp(eigenRotorsArray[1]) -
                 eigenRotorsArray[1].Gp(eigenRotorsArray[0]))
                .Round(7);

            Console.WriteLine("Difference:");
            Console.WriteLine(diff.TermsToLaTeX().GetLaTeXDisplayEquation());
            Console.WriteLine();


            var rs = GaPoTNumRotorsSequence.Create(
                eigenRotorsArray[0],
                eigenRotorsArray[1]
                );

            //var rs = GaPoTNumRotorsSequence.Create(
            //    eigenRotorsArray[0]
            //);

            var uFrame1 = rs.Rotate(cFrame);

            Console.WriteLine("Rotated cFrame:");

            for (var i = 0; i < n; i++)
            {
                Console.WriteLine(uFrame1[i].Round(7).TermsToLaTeX().GetLaTeXDisplayEquation());
                Console.WriteLine();
            }
        }