%**************************************************************************
%This function fits the slippage at the peak fields with a straight line.
%The end poles are to be excluded from the fit.  The residuals are
%also calculated.
%
%Input:
%z_peak_no_ends, z position of the peak fields excluding the ends (m)
%slip_peak_no_ends, slippage at the locations of the field peaks excluding the ends (m)
%
%Output:
%slope, slope of the linear fit of slippage vs z (dimensionless)
%intercept, intercept of the line fit to slippage vs z (dimensionless)
%slip_resid_peak_no_ends, residuals to the fit (m)
%
%Zachary Wolf, 4/15/04, 12/26/05, 6/26/10

function [slope, intercept, slip_resid_peak_no_ends] = slip_linfit_slip(z_peak_no_ends, slip_peak_no_ends)

%Fit a line to the slippage at the peaks
p = polyfit(z_peak_no_ends, slip_peak_no_ends, 1);
slope = p(1);
intercept = p(2);

%Find the residuals to the linear fit
slip_resid_peak_no_ends = slip_peak_no_ends - (slope * z_peak_no_ends + intercept);

%Done