[2696] | 1 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 2 | Matlab Gateway for the Hessian |
---|
| 3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
---|
| 4 | |
---|
| 5 | #include "mex.h" |
---|
| 6 | #define min( x, y ) (x) < (y) ? (x) : (y) |
---|
| 7 | #define max( x, y ) (x) > (y) ? (x) : (y) |
---|
| 8 | |
---|
| 9 | void mexFunction( int nlhs, mxArray *plhs[], |
---|
| 10 | int nrhs, const mxArray *prhs[] ) |
---|
| 11 | { |
---|
| 12 | int mrows, mcols; |
---|
| 13 | KPP_REAL *V, *F, *RCT, *HESS; |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | /* Check for the right number and size of input arguments */ |
---|
| 17 | if ( nrhs != 3 ) { |
---|
| 18 | mexErrMsgTxt("KPP_ROOT_Hessian requires 3 input vectors: V(KPP_NVAR), F(KPP_NFIX), RCT(KPP_NREACT)"); |
---|
| 19 | } |
---|
| 20 | mrows = mxGetM(prhs[0]); mcols = mxGetN(prhs[0]); |
---|
| 21 | if ( ( mrows != KPP_NVAR )||( mcols != 1 ) ) { |
---|
| 22 | mexPrintf("First KPP_ROOT_Hessian input argument is of size V(%d,%d).", |
---|
| 23 | mrows, mcols); |
---|
| 24 | mexErrMsgTxt("First KPP_ROOT_Hessian input argument should be a column vector V(KPP_NVAR,1)"); |
---|
| 25 | } |
---|
| 26 | mrows = mxGetM(prhs[1]); mcols = mxGetN(prhs[1]); |
---|
| 27 | if ( ( mrows != KPP_NFIX )||( mcols != 1 ) ) { |
---|
| 28 | mexPrintf("Second KPP_ROOT_Hessian input argument is of size F(%d,%d).", |
---|
| 29 | mrows, mcols); |
---|
| 30 | mexErrMsgTxt("Second KPP_ROOT_Hessian input argument should be a column vector F(KPP_NFIX,1)"); |
---|
| 31 | } |
---|
| 32 | mrows = mxGetM(prhs[2]); mcols = mxGetN(prhs[2]); |
---|
| 33 | if ( ( mrows != KPP_NREACT )||( mcols != 1 ) ) { |
---|
| 34 | mexPrintf("Third KPP_ROOT_Hessian input argument is of size RCT(%d,%d).", |
---|
| 35 | mrows, mcols); |
---|
| 36 | mexErrMsgTxt("Third KPP_ROOT_Hessian input argument should be a column vector RCT(KPP_NREACT,1)"); |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | /* Check for the right number of output arguments */ |
---|
| 40 | if ( nlhs != 1 ) { |
---|
| 41 | mexErrMsgTxt("KPP_ROOT_Hessian requires 1 output column vector: HESS(KPP_NHESS)"); |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | V = mxGetPr(prhs[0]); |
---|
| 46 | F = mxGetPr(prhs[1]); |
---|
| 47 | RCT = mxGetPr(prhs[2]); |
---|
| 48 | |
---|
| 49 | plhs[0] = mxCreateDoubleMatrix(KPP_NHESS,1,mxREAL); |
---|
| 50 | HESS = mxGetPr(plhs[0]); |
---|
| 51 | |
---|
| 52 | Hessian( V, F, RCT, HESS ); |
---|
| 53 | |
---|
| 54 | } |
---|