#include "mex.h"
#include "math.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {

double *X;
double *Y;
int i;
int m=0;


X = (double *) mxGetPr(prhs[0]);
m=(int)mxGetPr(prhs[1])[0];

plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
Y = (double *)mxGetPr(plhs[0]);


for (i=0;i<m;i++)
{
	*Y+=X[i]*X[i];
}

}