MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.Create C# (CSharp) Method

Create() public static method

Create a new dense matrix and initialize each value using the provided init function.
public static Create ( int rows, int columns, Func init ) : DenseMatrix
rows int
columns int
init Func
return DenseMatrix
        public static DenseMatrix Create(int rows, int columns, Func<int, int, double> init)
        {
            return new DenseMatrix(DenseColumnMajorMatrixStorage<double>.OfInit(rows, columns, init));
        }

Same methods

DenseMatrix::Create ( int rows, int columns, double value ) : DenseMatrix

Usage Example

Example #1
0
    private void HardConstraintsStep()
    {
        // Vectors and matrices to store data
        VectorXD C0 = new DenseVectorXD(m_numcs);
        VectorXD f  = new DenseVectorXD(m_numdofs);
        VectorXD v  = new DenseVectorXD(m_numdofs);
        MatrixXD M  = new DenseMatrixXD(m_numdofs, m_numdofs);
        MatrixXD J  = new DenseMatrixXD(m_numcs, m_numdofs);

        MatrixXD System      = new DenseMatrixXD(m_numcs + m_numdofs, m_numcs + m_numdofs);
        VectorXD Independent = new DenseVectorXD(m_numdofs + m_numcs);

        // Compute forces and retrieve the rigid bodies data
        foreach (ISimulable i in m_objs)
        {
            i.clearForcesAndMatrices();
            i.addForcesAndMatrices();

            i.getForceVector(f);
            i.getVelocityVector(v);
            i.getMassMatrix(M);
        }

        // Compute and retrieve restrictions and Jacobians
        foreach (Constraint c in m_constraints)
        {
            c.getConstraintVector(C0);
            c.getConstraintJacobian(J);
        }

        // Set up left-side system
        System.SetSubMatrix(0, m_numdofs, 0, m_numdofs, M);
        System.SetSubMatrix(m_numdofs, m_numcs, 0, m_numdofs, J);
        System.SetSubMatrix(0, m_numdofs, m_numdofs, m_numcs, J.Transpose());
        System.SetSubMatrix(m_numdofs, m_numcs, m_numdofs, m_numcs, DenseMatrixXD.Create(m_numcs, m_numcs, 0.0));

        // Set up right-side system
        VectorXD b    = M * v + TimeStep * f;
        VectorXD AtC0 = (-1.0f / TimeStep) * C0;

        Independent.SetSubVector(0, m_numdofs, b);
        Independent.SetSubVector(m_numdofs, m_numcs, AtC0);

        // Solve system
        VectorXD newVelocities = System.Solve(Independent);

        // Update bodies
        foreach (ISimulable i in m_objs)
        {
            i.setVelocityVector(newVelocities);
            i.advancePosition();
        }
    }
All Usage Examples Of MathNet.Numerics.LinearAlgebra.Double.DenseMatrix::Create