Exemplo n.º 1
0
        public static GaPoTNumVector TermsArrayToVector(int rowsCount, int columnsCount, int[] rowIndicesArray, int[] columnIndicesArray, double[] valuesArray)
        {
            var matrixData = GaNumMatlabSparseMatrixData.CreateMatrix(rowsCount, columnsCount, rowIndicesArray, columnIndicesArray, valuesArray);

            var mv = new GaPoTNumVector();

            mv.AddTerms(matrixData);

            return(mv);
        }
Exemplo n.º 2
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.º 3
0
        public static void DisplayFrame(GaPoTNumFrame frame)
        {
            var n = frame.Count;

            Console.WriteLine("Frame Matrix:");
            Console.WriteLine(frame.GetMatrix().GetLaTeXArray());
            Console.WriteLine();

            Console.WriteLine("Frame Inner Products Matrix:");
            Console.WriteLine(frame.GetInnerProductsMatrix().GetLaTeXArray());
            Console.WriteLine();

            Console.WriteLine("Frame Inner Angles Matrix:");
            Console.WriteLine(frame.GetInnerAnglesMatrix().GetLaTeXArray());
            Console.WriteLine();

            Console.WriteLine("Auto Vector Projection on Frame:");
            Console.WriteLine("$" + GaPoTNumVector.CreateAutoVector(n).GetProjectionOnFrame(frame).TermsToLaTeX() + "$");
            Console.WriteLine();
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
 public static GaPoTNumVector CreateBasisVector(int id)
 {
     return(GaPoTNumVector.CreateZero().AddTerm(id, 1.0d));
 }