private void calcDeriv(){

            if(this.numerDiffFlag){
                // Numerical differentiation using delta and interpolation
                this.cs = new CubicSpline(this.x, this.y);
    	        double[] xjp1 = new double[this.nPoints];
    	        double[] xjm1 = new double[this.nPoints];
    	        for(int i=0; i<this.nPoints; i++){
    	            xjp1[i] = this.x[i] + this.incrX;
    	            if(xjp1[i]>this.x[this.nPoints-1])xjp1[i] = this.x[this.nPoints-1];
    	            xjm1[i] = this.x[i] - this.incrX;
    	            if(xjm1[i]<this.x[0])xjm1[i] = this.x[0];
    	        }

    	        for(int i=0; i<this.nPoints; i++){
    	            this.dydx[i] = (cs.interpolate(xjp1[i]) - cs.interpolate(xjm1[i]))/(xjp1[i] - xjm1[i]);
                }
            }
            else{
                // Numerical differentiation using provided data points
                int iip =0;
                int iim =0;
                for(int i=0; i<this.nPoints; i++){
                    iip = i+1;
    	            if(iip>=this.nPoints)iip = this.nPoints-1;
    	            iim = i-1;
    	            if(iim<0)iim = 0;
    	            this.dydx[i] = (this.y[iip] - this.y[iim])/(this.x[iip] - this.x[iim]);
                }
            }
	    	this.derivCalculated = true;
    	}