
302 Programming for Chemical Engineers
HANDLING VECTORS
One Vector Input and One Scalar Output
So far we have only dealt with variables having one value. However, it is also
possible to develop a MEX-file with vector inputs. To illustrate, let us consider
a program that solves for the root of a 3
rd
order polynomial equation using the
Müller method.
Partial code has already been provided in Chapter 5’s Laboratory Exercise2,
which is then completed as a MEX-file.
Program Listing 9.4: Müller function
/* save as muller.c */
#include <math.h>
#include “mex.h”
void mexFunction( int nlhs, mxArray *plhs[], int nrhs,
const mxArray *prhs[])
{
double xr,h[3],d[3],a,b,c,fx[4],x[4],rad2,rad,dxr,den; ...