- Справка Scilab
- API Scilab
- legacy
- API Scilab
- API types
- Getting started with API_Scilab
- API double functions
- API common functions
- API string functions
- API boolean functions
- API integer functions
- API list-type functions
- API polynomial functions
- API pointer functions
- API cell functions
- API struct functions
- API handle functions
- API optional functions
Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
API polynomial functions
This page lists all the functions to manipulate Scilab native objects containing polynomials
scilabVar
scilab_createPolyMatrix
(
scilabEnv
env, const wchar_t* varname, int dim, const int* dims, int complex)
Create a polynomial matrix in varname
with dim
dimensions (dims
[0], dims
[1], ..., dims
[dim
-1]).
complex
: 0 to real matrix or 1 to complex matrix
scilabVar
scilab_createPolyMatrix2d
(
scilabEnv
env, const wchar_t* varname, int row, int col, int complex)
Create a matrix of polynomial in varname
with 2
dimensions M(row, col)
.
complex
: 0 to real matrix or 1 to complex matrix
scilabVar
scilab_createPoly
(
scilabEnv
env, const wchar_t* varname, int val, int complex)
Create a scalar polynomial in varname
.
complex
: 0 to real matrix or 1 to complex matrix
int scilab_getPolyVarname
(
scilabEnv
env,
scilabVar
var, const wchar_t** varname)
Fill varname
with polynomial symbol.
scilabStatus
scilab_getPolyArray
(
scilabEnv
env,
scilabVar
var, int index, double** real)
Get pointer on internal array of polynomial of var
at position index
.
scilabStatus
scilab_getComplexPolyArray
(
scilabEnv
env,
scilabVar
var, int index, double** real, double** img)
Get pointers on internal array of polynomial of var
at position index
.
scilabStatus
scilab_setPolyArray
(
scilabEnv
env,
scilabVar
var, int index, int rank, const double* real)
Set values of polynomial variable var
at position index
.
scilabStatus
scilab_setComplexPolyArray
(
scilabEnv
env,
scilabVar
var, int index, int rank, const double* real, const double* img)
Set values of complex polynomial variable var
at position index
.
Examples
#include "api_scilab.h" #include "Scierror.h" #include "localization.h" #include "sciprint.h" #include "sci_malloc.h" const char fname[] = "polynomial_test"; int sci_polynomial_test(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt opt, int nout, scilabVar* out) { int i = 0; int inr1 = 0; int inc1 = 0; int size1 = 0; double* in1 = NULL; int rank1 = 0; wchar_t* name1 = NULL; double* in2 = 0; int rank2 = 0; wchar_t* name2 = NULL; double* out1 = NULL; double* out2 = 0; if (nin != 2) { Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2); return STATUS_ERROR; } if (nout != 2) { Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), fname, 2); return STATUS_ERROR; } //in[0] : matrix 2d of polynomial if (scilab_isPoly(env, in[0]) == 0 || scilab_isMatrix(env, in[0]) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: A polynomial matrix expected.\n"), fname, 1); return STATUS_ERROR; } //scilab_getPolyVarname(env, in[0], &name1); size1 = scilab_getDim2d(env, in[0], &inr1, &inc1); //in[1] : polynomial if (scilab_isPoly(env, in[1]) == 0 || scilab_isScalar(env, in[1]) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: A polynomial expected.\n"), fname, 2); return STATUS_ERROR; } //scilab_getPolyVarname(env, in[1], &name2); rank2 = scilab_getPolyArray(env, in[1], 0, &in2); //out1 : matrix 2d of polynomial with same size of in[0] out[0] = scilab_createPolyMatrix2d(env, L"s", inr1, inc1, 0); for (i = 0; i < size1; ++i) { int j = 0; rank1 = scilab_getPolyArray(env, in[0], i, &in1); out1 = (double*)MALLOC((rank1 + 2) * sizeof(double));//+1 to grow and +1 because rank is (size - 1) out1[0] = 0; for (j = 0; j < rank1 + 1; ++j) { out1[j + 1] = in1[j]; } scilab_setPolyArray(env, out[0], i, rank1 + 1, out1); FREE(out1); } //out2 : polynomial -in2 out[1] = scilab_createPoly(env, L"s", 0); out2 = (double*)MALLOC((rank2 + 1) * sizeof(double)); for (i = 0; i < rank2 + 1; ++i) { out2[i] = -in2[i]; } scilab_setPolyArray(env, out[1], 0, rank2, out2); FREE(out2); return STATUS_OK; }
Scilab test script
mkdir(pathconvert(TMPDIR+"/api_c/")); cd(pathconvert(TMPDIR+"/api_c/")); copyfile(SCI+"/modules/api_scilab/tests/unit_tests/api_c/polynomial_test.c",pathconvert(TMPDIR+"/api_c/polynomial_test.c",%F)); ilib_build("libpolynomial",["polynomial_test","sci_polynomial_test", "csci6"],"polynomial_test.c",[],"","",""); exec("loader.sce"); in1 = [10, 4*%s + 8, -5 + 6*%s - 7*%s**2;10, 4*%s + 8, -5 + 6*%s - 7*%s**2], in2 = 1-%s**2; [out1, out2] = polynomial_test(in1, in2); assert_checkequal(out1, in1 *%s); assert_checkequal(out2, -in2); disp("OK");
Report an issue | ||
<< API list-type functions | API Scilab | API pointer functions >> |