Polynomial writing (Scilab gateway) — How to write matrices of polynomials in a gateway.
Input argument profile:
SciErr createMatrixOfPoly(void* _pvCtx, int _iVar, char* _pstVarName, int _iRows, int _iCols, int* _piNbCoef, double** _pdblReal)
SciErr createMatrixOfPoly(void* _pvCtx, int _iVar, char* _pstVarName, int _iRows, int _iCols, int* _piNbCoef, double** _pdblReal)
Named variable profile:
SciErr createNamedMatrixOfPoly(void* _pvCtx, char* _pstName, char* _pstVarName, int _iRows, int _iCols, int* _piNbCoef, double** _pdblReal)
SciErr createNamedComplexMatrixOfPoly(void* _pvCtx, char* _pstName, char* _pstVarName, int _iRows, int _iCols, int* _piNbCoef, double** _pdblReal, double** _pdblImg)
Scilab environment pointer, pass in "pvApiCtx" provided by api_scilab.h.
Position in the Scilab memory where you want to put the variable
Name of the variable for "named" functions.
Variable name in polynomials (Scilab5: 4 characters max)
Number of rows of the new variable
Numbers of columns of the new variable
Number of coefficient for each polynomial.
Address of array of double* with real part of coefficient (size: _iCols * _iRows)
Address of array of double* with imaginary part of coefficient (size: _iCols * _iRows)
Error structure where is stored errors messages history and first error number.
int write_poly(char *fname,unsigned long fname_len)
{
SciErr sciErr;
//output variable info : polinomial matrix 2 x 4
//[ x + 2 x^2 - 4x + 5 4x^3 - 14x^2 + 18 ;
// 2x^3 - 12x^2 + 64 1 8x^5 + 32x^3]
int iRows = 2;
int iCols = 3;
//varname "x"
char pstVarName[2] = {"x"};
//coeficient array
int piNbCoef[6] = {2,4,3,1,4,6};
//data array
double *pdblReal[6] = {0};
double pdblPoly0[2] = {2,1};
double pdblPoly1[4] = {64,0,-12,2};
double pdblPoly2[3] = {5,-4,1};
double pdblPoly3[1] = {1};
double pdblPoly4[4] = {18,0,-14,4};
double pdblPoly5[6] = {0,0,0,32,0,8};
pdblReal[0] = pdblPoly0;
pdblReal[1] = pdblPoly1;
pdblReal[2] = pdblPoly2;
pdblReal[3] = pdblPoly3;
pdblReal[4] = pdblPoly4;
pdblReal[5] = pdblPoly5;
sciErr = createMatrixOfPoly(pvApiCtx, Rhs + 1, pstVarName, iRows, iCols, piNbCoef, pdblReal);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
//assign allocated variables to Lhs position
LhsVar(1) = Rhs + 1;
return 0;
}