Rick, phi = GaussKernel(X, C, 0.025); /* use smaller bandwidth */ Should be phi = GaussKernel(Z, C, 0.025); /* use smaller bandwidth */ ?