简体   繁体   English

从另一个矩阵获取一个矩阵

[英]Get a Matrix from another Matrix

So guys, I'm developping a program for Structural Analysis and I came across a problem that I'm having some problem to solve. 伙计们,我正在开发一个用于结构分析的程序,遇到一个我要解决的问题。 Basically, I have a system of equations, of which I only need to solve some of them. 基本上,我有一个方程组,只需解决其中的一些问题。 The ones I need to solve depend on a boolean array, true if I do, false if I don't. 我需要解决的问题取决于布尔数组,如果我这样做,则为true,否则为false。 This way, having a true value in the nth element of the array means I'll have to solve the nth equation, therefore meaning that I have to get the nxn element of the matrix of the system of equations. 这样,在数组的第n个元素中具有真值意味着我将不得不求解第n个方程,因此这意味着我必须获得方程组矩阵的nxn个元素。 Do you guys have any insight on it? 你们对此有什么见识吗?

So, this is what I've come up with: 所以,这就是我想出的:

//Firstly, define the size of the subsystem:
    int size = 0;
    for(int i = 0; i < TrueorFalseMatrix.m; i++) {
        if(TrueorFalseMatrix.data[i][0] != 0) 
            size+= 1;
    }
    //Then we can assign the size values to the Matrix of the subsystem
    System_A = Matrix.matrizEmpty(size,size);
    System_B = Matriz.matrizEmpty(size, 1);
    //This array will store the coordinates of the coefficients that
    //will be used
    int[] Coordinates = new int[size];
    //We store these coordinates in the array
    int count = 0;
    for(int i = 0; i < TrueorFalseMatrix.m; i++) {
        if(TrueorFalseMatrix.data[i][0] != 0) {
            Dtrue[count] = i;
            count++;
        }
    }
    //We can now assign values to our system Matrix
    for(int i = 0; i < size; i++) {
        for(int j = 0; j < size; j++) {
            System_A.data[i][j] = SourceMatrix.data[Dtrue[i]][Dtrue[j]];
        }
        System_B.data[i][0] = SourceResultVector.data[Dtrue[i]][0]
    }
    //Results
    double[] Results = System.solve(System_A,System_B);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM