Oj-Algo - 矩阵指数

时间:2018-04-17 08:11:03

标签: java matrix ojalgo

我解决了以下等式:

enter image description here

要解决它,我想使用矩阵指数:

enter image description here

我想了3种方法:

  1. 我本可以错过它但是Oj-Algo可以有一种简单的方法来计算exp(A)(我没有在MatrixStore javadoc中找到它)
  2. 我从EigenValue方法得到矩阵D和V([A] = [V] [D] [V] -1 )然后我计算 enter image description here 那么首先问题是我如何将x-> exp(x * t)函数应用于D的所有对角线元素?
  3. 最后的想法与2.基本相同。但我之前将标量矩阵产品存储在一个新的矩阵中([X] = [D] *( - t)),然后我计算:
  4. enter image description here

    你能帮我找到我应该使用的最好的方法/类吗?谢谢你

    注意:这个问题是“跟进问题”:initial question

    编辑 : 这就是我现在尝试过的,这是最好的方法吗?

    import static org.ojalgo.function.PrimitiveFunction.EXP;
    
    
    public class SolveDifferentialEquationTest
    {
    
        private static final PhysicalStore.Factory<Double, PrimitiveDenseStore> matrixFactory = PrimitiveDenseStore.FACTORY;
    
        public static void main(String[] args)
        {
            SparseStore<Double> matrix;
            final PhysicalStore<Double> diagMatrix;
            final PhysicalStore<Double> eigenVectorMatrix;
            final PhysicalStore<Double> inverseEigenVectorMatrix;
            final Eigenvalue<Double> eigenvalue;
            final int time = 100;
            PhysicalStore<Double> initialVector;
            final PhysicalStore<Double> finalVector;
    
            int dim = 2000;
            matrix = SparseStore.PRIMITIVE.make(dim, dim);
            initialVector = matrixFactory.makeZero(dim,1);
    
            // fill matrix and initialVector
            //...
    
            //Decompose matrix
    
            eigenvalue = Eigenvalue.PRIMITIVE.make(matrix);
            eigenvalue.decompose(matrix);
            diagMatrix = eigenvalue.getD().copy();
            eigenVectorMatrix = eigenvalue.getV().copy();
            InverterTask<Double> inverter = InverterTask.PRIMITIVE.make(eigenVectorMatrix);
            try {
                inverseEigenVectorMatrix = inverter.invert(eigenVectorMatrix).copy();
            } catch (RecoverableCondition e) {
                throw new RuntimeException(e);
            }
    
            // Construct exp(Dt)
            diagMatrix.multiply(time);
            diagMatrix.modifyDiagonal(EXP);
    
            // Compute
            finalVector = inverseEigenVectorMatrix.multiply(diagMatrix)
                                                  .multiply(eigenVectorMatrix)
                                                  .multiply(initialVector)
                                                  .copy();
        }
    }
    

0 个答案:

没有答案