# Is there a built-in function implementing the minimum and maximum gradient?

Suppose I have a set of data. Mathematica has fitting functions to determine the line and corresponding equation to the best fit given any arbitrary set of data.

But in experimental techniques, another two lines known as the minimum and maximum gradient is require. The maximum gradient is the line that passes through all error bars but for the data on the extreme right the line passes through the top of the error bars.

For the minimum gradient, this line passes through all the error bars but for data on the extreme left, this line passes through the bottom of the error bars.

Does Mathematica have any sort of built-in function that would enable me to do so?

AFAIK - no. But since you asking. Suppose you have this Data:

xdata = {1, 2, 3, 4, 5};
ydata = {1, 2, 3, 4, 5};


and this Errors:

err1 = 0.3
err2 = 0.35


Giving you

lp1 = ListPlot[{xdata, ydata}, PlotStyle -> Green]


and

lm = LinearModelFit[Transpose[{xdata, ydata}], x, x]
lm["BestFit"]


-3.57485*10^-15 + 1. x

p1 = Plot[{lm[x]}, {x, maX + 1, miN - 1}, PlotStyle -> Blue, AspectRatio -> 1]


You can estimate minimum and maximum gradient like so:

myerR = (err1 + err2)/2;
lp2 = ListLinePlot[{{1 + myerR, 1 - myerR}, {5 - myerR, 5 + myerR}}, Mesh -> Full]


lp3 = ListLinePlot[{{1 - myerR, 1 + myerR}, {5 + myerR, 5 - myerR}}, Mesh -> Full]


And the ErrorListPlot:

elp1 = ErrorListPlot[{{{1, 1}, ErrorBar[err1, err2]}, {{2, 2},
ErrorBar[err1, err2]}, {{3, 3}, ErrorBar[err1, err2]}, {{4, 4},
ErrorBar[err1, err2]}, {{5, 5}, ErrorBar[err1, err2]}},
PlotStyle -> Red]


Combining all in one Plot and spicing Graphics up for Reasons of instruction:

Show[Graphics[{
LightBlue,
Rectangle[{1 - myerR, 1 - myerR}, {1 + myerR, 1 + myerR}],
LightBlue, Rectangle[{5 - myerR, 5 - myerR}, {5 + myerR, 5 + myerR}]
}],
p1, elp1, lp1, lp2, lp3, Frame -> True]


Should not be a problem to find LinearModelFit for minimum and maximum gradient.

Have Fun!