Пример #1
0
        public static void ComputePower()
        {
            var n = 4;

            var uFrame = GaPoTNumFrame.CreateBasisFrame(n);
            var cFrame = GaPoTNumFrame.CreateGramSchmidtFrame(n, n - 1);

            var rotorsSequence =
                GaPoTNumRotorsSequence.Create(
                    cFrame.GetRotorsToFrame(uFrame)
                    );

            var v = "-4<1>, 8<2>, -3<3>, -1<4>".GaPoTNumParseVector();
            var i = "-9<1>, 2<2>, -5<3>, 12<4>".GaPoTNumParseVector();

            var m = v.Gp(i);

            var vr = rotorsSequence.Rotate(v);
            var ir = rotorsSequence.Rotate(i);

            var mr = vr.Gp(ir);

            Console.WriteLine($"m  = {m.TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine($"mr = {mr.TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine();
        }
Пример #2
0
        //public static void DisplayGramSchmidtToClarkeMatrices()
        //{
        //    for (var n = 2; n <= 12; n++)
        //    {
        //        var matrix1 = GaPoTNumFrame.CreateGramSchmidtFrame(n).GetMatrix(n);
        //        var matrix2 = GaPoTNumFrame.CreateClarkeFrame(n).GetMatrix(n);
        //        var matrix = Mfs.Dot[matrix2, Mfs.Transpose[matrix1]];

        //        Console.WriteLine($"m{n} = {matrix};");
        //        Console.WriteLine($"MatrixForm[FullSimplify[m{n}]]");
        //        Console.WriteLine($"MatrixForm[FullSimplify[Dot[m{n}, Transpose[m{n}]]]]");
        //        Console.WriteLine();
        //    }
        //}

        public static void DisplayGramSchmidtToClarkeRotors()
        {
            var n = 4;

            var frame1 = GaPoTNumFrame.CreateGramSchmidtFrame(n).GetSwappedPairsFrame();
            var frame2 = GaPoTNumFrame.CreateClarkeFrame(n);

            var rotorsSequence = GaPoTNumRotorsSequence.Create(
                frame1.GetRotorsToFrame(frame2)
                );

            var i = 1;

            foreach (var rotor in rotorsSequence)
            {
                Console.WriteLine($"R_{i} = {rotor.TermsToLaTeX()}");
                Console.WriteLine();

                i++;
            }
        }
Пример #3
0
        public static void DisplayFrame(GaPoTNumFrame sourceFrame, GaPoTNumFrame targetFrame)
        {
            var n = targetFrame.Count;

            var matrixExpr = targetFrame.GetMatrix(n);

            var orthoFrameEquation = targetFrame.ToLaTeXEquationsArray(
                "c",
                @"\mu"
                );

            Console.WriteLine(orthoFrameEquation);
            Console.WriteLine();

            Console.WriteLine("Rotation Matrix:");
            Console.WriteLine();

            Console.WriteLine($@"\[{matrixExpr.GetLaTeXArray()}\]");
            Console.WriteLine();

            var anglesTextList = sourceFrame
                                 .GetAnglesToFrame(targetFrame)
                                 .Select(a => a.GetLaTeXAngleInDegrees())
                                 .ToArray();

            Console.WriteLine("Angles between frames vectors:");
            foreach (var angleText in anglesTextList)
            {
                Console.WriteLine($@"\[{angleText}\]");
                Console.WriteLine();
            }

            var autoVectorProjection = GaPoTNumVector
                                       .CreateAutoVector(n)
                                       .GetProjectionOnFrame(targetFrame);

            Console.WriteLine("Projection of auto-vector:");
            Console.WriteLine($@"\[{autoVectorProjection.TermsToLaTeX()}\]");
            Console.WriteLine();

            var rotorsSequence =
                GaPoTNumRotorsSequence.Create(
                    sourceFrame.GetRotorsToFrame(targetFrame)
                    );

            //if (!rotorsSequence.ValidateRotation(sourceFrame, targetFrame))
            //    throw new InvalidOperationException("Error in rotation sequence");

            //for (var i = 0; i < sourceFrame.Count - 1; i++)
            //{
            //    var f1 = sourceFrame.GetSubFrame(0, i + 1);
            //    var f2 = targetFrame.GetSubFrame(0, i + 1);
            //    var rs = rotorsSequence.GetSubSequence(0, i + 1);

            //    if (!rs.ValidateRotation(f1, f2))
            //        throw new InvalidOperationException("Error in rotation sequence");
            //}

            Console.WriteLine("Rotors Sequence:");
            Console.WriteLine();

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

                Console.WriteLine(rotorEquation);
                Console.WriteLine();
            }

            if (n > 4)
            {
                return;
            }

            //var rotor21 = rotorsSequence[1].Gp(rotorsSequence[0]);
            //var rotor21Equation = rotor21.ToLaTeXEquationsArray(
            //    $"R_{{21}}=R_2 R_1",
            //    @"\mu"
            //);

            //Console.WriteLine(rotor21Equation);
            //Console.WriteLine();

            //var rotor32 = rotorsSequence[2].Gp(rotorsSequence[1]);
            //var rotor32Equation = rotor32.ToLaTeXEquationsArray(
            //    $"R_{{32}}=R_3 R_2",
            //    @"\mu"
            //);

            //Console.WriteLine(rotor32Equation);
            //Console.WriteLine();

            Console.WriteLine("Final Rotor $R = R_3 R_{21} = R_{32} R_1$:");
            Console.WriteLine();

            var finalRotor         = rotorsSequence.GetFinalRotor();
            var finalRotorEquation = finalRotor.ToLaTeXEquationsArray(
                "R",
                @"\mu"
                );

            Console.WriteLine(finalRotorEquation);
            Console.WriteLine();

            //Console.WriteLine($"m{n} = {matrixExpr};");
            //Console.WriteLine($"MatrixForm[FullSimplify[m{n}]]");
            //Console.WriteLine($"MatrixForm[FullSimplify[Dot[m{n}, Transpose[m{n}]]]]");
            //Console.WriteLine($"Pseudo-Scalar = {frame.GetPseudoScalar()}");
            //Console.WriteLine();
        }
Пример #4
0
        public static void Execute()
        {
            var n = 4;

            var uFrame = GaPoTNumFrame.CreateBasisFrame(n);
            var cFrame = GaPoTNumFrame.CreateGramSchmidtFrame(n, n - 1, out var eFrame);

            var eFrameEquation = eFrame.ToLaTeXEquationsArray(
                "e",
                @"\mu"
                );

            Console.WriteLine("e-frame:");
            Console.WriteLine(eFrameEquation);
            Console.WriteLine();

            var cFrameEquation =
                cFrame.ToLaTeXEquationsArray(
                    "c",
                    @"\mu"
                    );

            Console.WriteLine("c-frame:");
            Console.WriteLine(cFrameEquation);
            Console.WriteLine();

            var cFrameMatrix =
                cFrame.GetMatrix().GetLaTeXArray();

            Console.WriteLine("c-frame matrix:");
            Console.WriteLine(cFrameMatrix);
            Console.WriteLine();

            var rotorsSequence =
                GaPoTNumRotorsSequence.Create(
                    cFrame.GetRotorsToFrame(uFrame)
                    );

            var finalRotor =
                rotorsSequence.GetFinalRotor();

            var R1 = rotorsSequence[1].Gp(rotorsSequence[0]);
            var R2 = rotorsSequence[2];

            var autoVector = GaPoTNumVector.CreateAutoVector(n);

            var rotatedAutoVector =
                rotorsSequence.Rotate(autoVector);

            var v1 = Math.Sqrt(2) * Math.Cos(0);
            var v2 = Math.Sqrt(2) * Math.Cos(0 - 1 * 2 * Math.PI / 4);
            var v3 = Math.Sqrt(2) * Math.Cos(0 - 2 * 2 * Math.PI / 4);
            var v4 = -(v1 + v2 + v3);

            var inputVector = new GaPoTNumVector()
                              .AddTerm(1, v1)
                              .AddTerm(2, v2)
                              .AddTerm(3, v3)
                              .AddTerm(4, v4);

            Console.WriteLine("Final Rotor:");
            Console.WriteLine($"{finalRotor.TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine($"{finalRotor.TermsToText()}");
            Console.WriteLine();

            Console.WriteLine("R1:");
            Console.WriteLine($"{R1.TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            Console.WriteLine("R2:");
            Console.WriteLine($"{R2.TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            Console.WriteLine("R2 R1 - R:");
            Console.WriteLine($"{(R2.Gp(R1) - finalRotor).TermsToText()}");
            Console.WriteLine($"{(R1.Gp(R2) - finalRotor).TermsToText()}");
            Console.WriteLine();

            Console.WriteLine("Rotated Auto Vector:");
            Console.WriteLine($"{rotatedAutoVector.TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            Console.WriteLine("Input Vector:");
            Console.WriteLine($"{inputVector.TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            var rotatedVector =
                rotorsSequence.Rotate(inputVector);

            Console.WriteLine("Rotated Vector:");
            Console.WriteLine($"{rotatedVector.TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            Console.WriteLine("Rotated Vector . Rotated Auto Vector:");
            Console.WriteLine($"{rotatedVector.DotProduct(rotatedAutoVector):G}");
            Console.WriteLine();

            var eI = eFrame.GetPseudoScalar();

            Console.WriteLine("Input Vector inside e-frame: ");
            Console.WriteLine($"{inputVector.Op(eI).TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine();

            Console.WriteLine("Rotated Vector inside e-frame: ");
            Console.WriteLine($"{rotatedVector.Op(eI).TermsToLaTeX().GetLaTeXDisplayEquation()}");
            Console.WriteLine();


            Console.WriteLine("Input Vector squared norm: ");
            Console.WriteLine($"{inputVector.Norm2()}");
            Console.WriteLine();

            Console.WriteLine("Rotated Vector squared norm: ");
            Console.WriteLine($"{rotatedVector.Norm2()}");
            Console.WriteLine();
        }
Пример #5
0
        public static void Execute()
        {
            var n = 3;

            var uFrame = GaPoTNumFrame.CreateBasisFrame(n);
            var cFrame = GaPoTNumFrame.CreateGramSchmidtFrame(n, n - 1, out var eFrame);

            var rotorsSequence =
                GaPoTNumRotorsSequence.Create(
                    uFrame.GetRotorsToFrame(cFrame)
                    ).Reverse();

            var finalRotor =
                rotorsSequence.GetFinalRotor();

            var autoVector = GaPoTNumVector.CreateAutoVector(n);

            var rotatedAutoVector =
                rotorsSequence.Rotate(autoVector);


            //var v1 = Math.Sqrt(2);
            //var v2 = Math.Sqrt(2) * Math.Cos(-Math.PI / 3);
            //var v3 = Math.Sqrt(2) * Math.Cos(Math.PI / 3);

            var v1 = 1.0d;
            var v2 = Math.Cos(-2 * Math.PI / 3);
            var v3 = Math.Cos(2 * Math.PI / 3);

            var inputVector = new GaPoTNumVector()
                              .AddTerm(1, v1)
                              .AddTerm(2, v2)
                              .AddTerm(3, v3);

            Console.WriteLine("Final Rotor:");
            Console.WriteLine($"{finalRotor.TermsToLaTeX()}");
            Console.WriteLine();

            Console.WriteLine("Rotated Auto Vector:");
            Console.WriteLine($"{rotatedAutoVector.TermsToLaTeX()}");
            Console.WriteLine();

            Console.WriteLine("Input Vector:");
            Console.WriteLine($"{inputVector.TermsToLaTeX()}");
            Console.WriteLine();

            var rotatedVector =
                rotorsSequence.Rotate(inputVector);

            Console.WriteLine("Rotated Vector:");
            Console.WriteLine($"{rotatedVector.TermsToLaTeX()}");
            Console.WriteLine();

            Console.WriteLine("Rotated Vector . Rotated Auto Vector:");
            Console.WriteLine($"{rotatedVector.DotProduct(rotatedAutoVector):G}");
            Console.WriteLine();

            var eI = eFrame.GetPseudoScalar();

            Console.WriteLine("Input Vector inside e-frame: ");
            Console.WriteLine($"{inputVector.Op(eI).TermsToLaTeX()}");
            Console.WriteLine();

            Console.WriteLine("Rotated Vector inside e-frame: ");
            Console.WriteLine($"{rotatedVector.Op(eI).TermsToLaTeX()}");
            Console.WriteLine();


            Console.WriteLine("Input Vector squared norm: ");
            Console.WriteLine($"{inputVector.Norm2()}");
            Console.WriteLine();

            Console.WriteLine("Rotated Vector squared norm: ");
            Console.WriteLine($"{rotatedVector.Norm2()}");
            Console.WriteLine();
        }
        private static void DisplayFrames(GaPoTNumFrame sourceFrame, GaPoTNumFrame kirchhoffFrame, GaPoTNumFrame targetFrame)
        {
            var n      = sourceFrame.Count;
            var matrix = targetFrame.GetMatrix(n);

            var kirchhoffFrameEquation = kirchhoffFrame.ToLaTeXEquationsArray(
                "e",
                @"\mu"
                );

            Console.WriteLine("Kirchhoff Frame:");
            Console.WriteLine(kirchhoffFrameEquation);
            Console.WriteLine();


            var projectedFrameMatrix = sourceFrame
                                       .GetProjectionOnFrame(kirchhoffFrame)
                                       .GetMatrix(n)
                                       .GetLaTeXArray();

            Console.WriteLine("Projected Frame Matrix:");
            Console.WriteLine(projectedFrameMatrix);
            Console.WriteLine();


            var orthoFrameEquation = targetFrame.ToLaTeXEquationsArray(
                "c",
                @"\mu"
                );

            Console.WriteLine("Orthonormal Frame:");
            Console.WriteLine(orthoFrameEquation);
            Console.WriteLine();


            Console.WriteLine("Rotation Matrix:");
            Console.WriteLine($"{matrix.GetLaTeXArray()}");
            Console.WriteLine();

            var anglesTextList = sourceFrame
                                 .GetAnglesToFrame(targetFrame)
                                 .Select(a => "$" + a.GetLaTeXAngleInDegrees() + "$")
                                 .ToArray();

            Console.WriteLine("Angles between frames vectors:");
            foreach (var angleText in anglesTextList)
            {
                Console.WriteLine($"{angleText}");
                Console.WriteLine();
            }

            var rotorsSequence =
                GaPoTNumRotorsSequence.Create(
                    sourceFrame.GetRotorsToFrame(targetFrame)
                    );

            //if (!rotorsSequence.ValidateRotation(sourceFrame, targetFrame))
            //    throw new InvalidOperationException("Error in rotation sequence");

            //for (var i = 0; i < sourceFrame.Count - 1; i++)
            //{
            //    var f1 = sourceFrame.GetSubFrame(0, i + 1);
            //    var f2 = targetFrame.GetSubFrame(0, i + 1);
            //    var rs = rotorsSequence.GetSubSequence(0, i + 1);

            //    if (!rs.ValidateRotation(f1, f2))
            //        throw new InvalidOperationException("Error in rotation sequence");
            //}

            Console.WriteLine("Rotors Sequence:");
            Console.WriteLine();

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

                Console.WriteLine(rotorEquation);
                Console.WriteLine();
            }

            //var rotor12Equation = rotorsSequence[1].Gp(rotorsSequence[0]).ToLaTeXEquationsArray(
            //    $"R_{{12}}",
            //    @"\mu"
            //);

            //Console.WriteLine(rotor12Equation);
            //Console.WriteLine();

            //var rotor23Equation = rotorsSequence[2].Gp(rotorsSequence[1]).ToLaTeXEquationsArray(
            //    $"R_{{23}}",
            //    @"\mu"
            //);

            //Console.WriteLine(rotor23Equation);
            //Console.WriteLine();

            Console.WriteLine("Final Rotor:");
            Console.WriteLine();

            var finalRotorEquation = rotorsSequence.GetFinalRotor().ToLaTeXEquationsArray(
                "R",
                @"\mu"
                );

            Console.WriteLine(finalRotorEquation);
            Console.WriteLine();
        }
Пример #7
0
 public static GaPoTNumRotorsSequence CreateRotorsSequence(GaPoTNumFrame sourceFrame, GaPoTNumFrame targetFrame)
 {
     return(GaPoTNumRotorsSequence.Create(
                sourceFrame.GetRotorsToFrame(targetFrame)
                ));
 }
Пример #8
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();
            }
        }