# How to fix problem with MATLAB GPML regression oscillations

I am having a problem with the GPML (Gaussian Processes for Machine Learning) tool in MATLAB. I have distilled my actual problem down to this basic demonstration below. Although the training points are linear, the GPML regression has oscillations that make the estimates significantly inaccurate, especially near the end points. The following plots are with length scales 0.25 and 1.75 respectively.

The code I am using to create these plots is

meanfunc = {@meanConst};  hyp.mean = 2;
covfunc = {'covSEiso'}; ell = 1.75; sf = 0.2; hyp.cov = log([ell; sf]);
likfunc = @likGauss; sn = 0.01; hyp.lik = log(sn);

nlml = gp(hyp, @infExact, meanfunc, covfunc, likfunc, x2, error2);


There is no length scale that will yield a linear prediction. Is there another covariance function or likelihood function that I should be using for linear data?

Note: My dataset is actually more complicated, but it exibits these problems near the end points.