如何查找矩阵 Scilab API 的行列式

问题描述 投票:0回答:1

我正在尝试使用 SciDet 函数计算矩阵的行列式,但显然它刚刚被删除。如何通过 C 代码以另一种方式计算 Scilab 中矩阵的行列式?

代码:

#include "api_scilab.h" // Header file for using SciLab API functions
#include "Scierror.h" // Header file for handling SciLab errors
#include "BOOL.h" // Header file for using BOOL type
#include "localization.h" // Header file for string localization

static const char fname[] = "det"; // Function name

int sci_det(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt* opt, int nout, scilabVar* out)
{
    int i = 0; // Loop variable
    int n = 0; // Dimension of the system
    double* A = NULL; // Coefficient matrix
    int info; // Error code variable
    double determinant = 1.0; // Determinant

    /* Check the number of input and output arguments */
    if (nin != 1 || nout != 1) {
        Scierror(77, _("%s: Wrong number of input or output arguments: 1 input and 1 output expected.\n"), fname); // Error message output
        return 1; // Return 1 in case of error
    }

    /* Check the types of input arguments */
    if (scilab_isDouble(env, in[0]) == 0 || scilab_isMatrix2d(env, in[0]) == 0 ||
        scilab_isComplex(env, in[0]) == 1) {
        Scierror(999, _("%s: Wrong type for input argument. Double matrix expected.\n"), fname); // Error message output
        return 1; // Return 1 in case of error
    }

    /* Get the dimensions of the coefficient matrix */
    int rowA = 0, colA = 0;
    scilab_getDim2d(env, in[0], &rowA, &colA); // Get matrix dimensions
    n = rowA; // Store the dimension

    /* Check that matrix A is square */
    if (rowA != colA) {
        Scierror(999, _("%s: Matrix of coefficients must be square.\n"), fname); // Error message output
        return 1; // Return 1 in case of error
    }

    /* Get data from the input argument */
    scilab_getDoubleArray(env, in[0], &A); // Get data from the input matrix

    /* Calculate the determinant */
    // Your determinant calculation code here

    return 0; // Return 0 upon successful execution
}

编译:

files = ["foo6.c"];
ilib_build('build_lib',['det','sci_det','csci6'],files,[]);
--> exec("loader.sce"); 
Failed reference for dynamic library '/home/zoow/Рабочий стол/ScilabAPI/Matrix/Test//libbuild_lib.so'.
There's been a mistake: /home/zoow/Рабочий стол/ScilabAPI/Matrix/Test//libbuild_lib.so: undefined symbol: sciDet
Failed reference for dynamic library '/home/zoow/Рабочий стол/ScilabAPI/Matrix/Test//libbuild_lib.so'.
There's been a mistake: /home/zoow/Рабочий стол/ScilabAPI/Matrix/Test//libbuild_lib.so: undefined symbol: sciDet
on line 15 of the executable /home/zoow/Рабочий стол/ScilabAPI/Matrix/Test/loader.sce

addinter: The shared archive has not been downloaded: (null)

我可以在代码中计算行列式,但我需要在 Scilab 中计算它并将值传递给 C

c ubuntu scilab
1个回答
0
投票

您可以使用 det 功能。请参阅帮助说明

© www.soinside.com 2019 - 2024. All rights reserved.