protected virtual void ComputeMappingMatrix() { var matrixItems = new Expr[TargetGaSpaceDimension, DomainGaSpaceDimension]; for (var col = 0; col < DomainGaSpaceDimension; col++) { var mv = this[col]; if (mv.IsNullOrZero()) { for (var row = 0; row < TargetGaSpaceDimension; row++) { matrixItems[row, col] = Expr.INT_ZERO; } continue; } for (var row = 0; row < TargetGaSpaceDimension; row++) { var scalar = mv[row]; matrixItems[row, col] = scalar.IsNullOrZero() ? Expr.INT_ZERO : scalar; } } InternalMappingMatrix = MathematicaMatrix.CreateFullMatrix(SymbolicUtils.Cas, matrixItems); }
public static MathematicaMatrix ToMatrix(this IGaSymMapUnilinear linearMap) { return(MathematicaMatrix.CreateFullMatrix( SymbolicUtils.Cas, ToExprScalarsArray(linearMap) )); }
public static void ConstructionTest() { TestUtils.AddTestStartingMessage("MathematicaMatrix Creation Test Started."); var scalarsArray = new MathematicaScalar[2, 2]; scalarsArray[0, 0] = MathematicaScalar.Create(Cas, 2); scalarsArray[0, 1] = MathematicaScalar.Create(Cas, -2); scalarsArray[1, 0] = MathematicaScalar.Create(Cas, 3); scalarsArray[1, 1] = MathematicaScalar.Create(Cas, 1); var s = MathematicaMatrix.CreateFullMatrix(Cas, scalarsArray); TestUtils.AddTest("Try create full matrix from array of scalars ... ", s); s = MathematicaMatrix.CreateIdentity(Cas, 3); TestUtils.AddTest("Try create full 3x3 identity matrix ... ", s); s = MathematicaMatrix.CreateIdentity(Cas, 3, false); TestUtils.AddTest("Try create sparse 3x3 identity matrix ... ", s); var v = MathematicaVector.CreateFullVector(Cas, Cas.Constants.Zero, Cas.Constants.TwoPi, Cas.Constants.One); s = MathematicaMatrix.CreateDiagonal(v); TestUtils.AddTest("Try create full 3x3 diagonal matrix from vector {0, 2 Pi, 1} ... ", s); s = MathematicaMatrix.CreateDiagonal(v, false); TestUtils.AddTest("Try create sparse 3x3 diagonal matrix from vector {0, 2 Pi, 1} ... ", s); s = MathematicaMatrix.CreateRowVector(v); TestUtils.AddTest("Try create full row vector matrix from vector {0, 2 Pi, 1} ... ", s); s = MathematicaMatrix.CreateRowVector(v, false); TestUtils.AddTest("Try create sparse row vector matrix from vector {0, 2 Pi, 1} ... ", s); s = MathematicaMatrix.CreateColumnVector(v); TestUtils.AddTest("Try create full row vector matrix from vector {0, 2 Pi, 1} ... ", s); s = MathematicaMatrix.CreateColumnVector(v, false); TestUtils.AddTest("Try create sparse row vector matrix from vector {0, 2 Pi, 1} ... ", s); s = MathematicaMatrix.CreateConstant(Cas.Constants.Pi, 2, 3); TestUtils.AddTest("Try create 2x3 matrix with constant elements of Pi ... ", s); s = MathematicaMatrix.Create(Cas, @"{{1, x}, {2, y}, {3, z}}"); TestUtils.AddTest("Try create matrix from expression text \"{{1, x}, {2, y}, {3, z}}\" ... ", s); TestUtils.AddTestCompletionMessage("MathematicaMatrix Creation Test Completed."); }
private void ComputeMultivectorTransformMatrix() { var matrixArray = new MathematicaScalar[CodomainGaSpaceDim, DomainGaSpaceDim]; for (var col = 0; col < DomainGaSpaceDim; col++) { var mv = _transformedBasisBlades[col]; foreach (var term in mv) { matrixArray[term.Key, col] = term.Value; } } _multivectorTransformMatrix = MathematicaMatrix.CreateFullMatrix(CasInterface, matrixArray); }
//public GAOuterMorphismFull(ISymbolicMatrix vector_transform_matrix) // : base(vector_transform_matrix.CAS) //{ // int domain_ga_space_dim = GAUtils.GASpaceDim(vector_transform_matrix.Columns); // int codomain_ga_space_dim = GAUtils.GASpaceDim(vector_transform_matrix.Rows); // _TransformedBasisBlades = new Multivector[domain_ga_space_dim]; // _TransformedBasisBlades[0] = Multivector.CreateScalar(codomain_ga_space_dim, MathematicaScalar.Create(CAS, 1)); // for (int id = 1 ; id <= domain_ga_space_dim - 1) // { // if (GAUtils.is_ID_Vector(id)) // { // _TransformedBasisBlades[id] = CreateFromMatrixColumn(vector_transform_matrix, GAUtils.ID_To_Index(id)); // } // else // { // int id1, id2; // GAUtils.SeparateIDs(id, out id1, out id2); // _TransformedBasisBlades[id] = Multivector.OuterProduct(_TransformedBasisBlades[id1], _TransformedBasisBlades[id2]); // } // } //} private void ComputeVectorTransformMatrix() { var matrixArray = new MathematicaScalar[CodomainVSpaceDim, DomainVSpaceDim]; for (var col = 0; col < DomainVSpaceDim; col++) { var id = FrameUtils.BasisBladeId(1, col); var mv = _transformedBasisBlades[id]; foreach (var term in mv) { var row = term.Key.BasisBladeIndex(); matrixArray[row, col] = term.Value; } } _vectorTransformMatrix = MathematicaMatrix.CreateFullMatrix(CasInterface, matrixArray); }
/// <summary> /// Create a derived frame system where the derived frame is the reciprocal of the base frame /// </summary> /// <param name="baseFrame"></param> /// <returns></returns> public static GaSymMetricNonOrthogonal CreateReciprocalCbmFrameSystem(GaSymFrame baseFrame) { if (baseFrame.IsOrthogonal) { var cbmat = baseFrame.Ipm.Inverse(); var b2DOm = baseFrame.Ipm.ToOutermorphismTree(); var d2BOm = cbmat.ToOutermorphismTree(); var derivedFrame = CreateOrthogonal(cbmat.GetDiagonal()); return(new GaSymMetricNonOrthogonal(baseFrame, derivedFrame, d2BOm, b2DOm)); } var cbmArray = new MathematicaScalar[baseFrame.VSpaceDimension, baseFrame.VSpaceDimension]; var mv2 = baseFrame.CreateInverseUnitPseudoScalar(); for (var i = 0; i < baseFrame.VSpaceDimension; i++) { var id = (1 << i) ^ baseFrame.MaxBasisBladeId; var mv1 = GaSymMultivector.CreateTerm(baseFrame.GaSpaceDimension, id, SymbolicUtils.Constants.One); var mv = baseFrame.Lcp[mv1, mv2]; foreach (var term in mv.NonZeroTerms) { var j = term.Key.BasisBladeIndex(); if ((i & 1) == 1) { cbmArray[i, j] = term.Value; } else { cbmArray[i, j] = -term.Value; } } } var cbm = MathematicaMatrix.CreateFullMatrix(SymbolicUtils.Cas, cbmArray); return(CreateDerivedCbmFrameSystem(baseFrame, cbm)); }