function   pumpcurve
% pumpcurve  Create a pump curve from discrete performance data

% -- Data for a Goulds pump model GT10
%    From Grainger's catalog
%    https://www.grainger.com/product/GOULDS-WATER-TECHNOLOGY-1-HP-Centrifugal-Pump-1N440
%
% 1 HP Centrifugal Pump, 115/230 Voltage, 1-1/2 Inlet (In.), 1-1/2 Outlet (In.)
% Item# 1N440 Mfr. Model# GT10 Catalog Page# 3299 UNSPSC# 40151503
%
% Data from Technical Specs section of web page in Grainger catalog
%
% 60 GPM @ 10 PSI
% 56 GPM @ 15 PSI
% 53 GPM @ 20 PSI
% 47 GPM @ 25 PSI
% 43 GPM @ 30 PSI
% 38 GPM @ 35 PSI
% 29 GPM @ 40 PSI
% 18 GPM @ 45 PSI

q = [60 56 53 47 43 38 29 18];  %  Flow rate in GPM
h = [10 15 20 25 30 35 40 45];  %  Head in PSI

% -- Set up and solve the system equations for interpolating the data
%    There are 8 data points from the catalog, so we can create a 
%    7th order polynomial.  This is a bad idea, but we'll do it anyway
A = [ q(:).^7  q(:).^6  q(:).^5  q(:).^4  q(:).^3  q(:).^2  q(:) ones(size(q(:))) ] ;
c = A\h(:);

% -- Evaluate the interpolating function at a large number of points in the
%    range of the original data
qplot = linspace( min(q), max(q) );
hplot = c(1)*qplot.^7 + c(2)*qplot.^6 + c(3)*qplot.^5  + c(4)*qplot.^4 ...
        + c(5)*qplot.^3 + c(6)*qplot.^2 + c(7)*qplot + c(8);

plot(q,h,'ko',qplot,hplot,'-')
xlabel('Flow rate (GPM)')
ylabel('Head (PSI)')
legend('Catalog data','7th order Interpolant','Cubic curve fit')

end

