%**************************************************************************
%This function calculates the K value given the gap.
%
%Input:
%gap, undulator gap (m)
%
%Output:
%k, undulator K value
%
%Zachary Wolf
%08/26/2016

function [k] = gap2k(gap)

%Parameters:
lambda_u = 0.032000;  %(m)
p(1) = -112080.913758;
p(2) = 521805.265835;
p(3) = -1081599.394642;
p(4) = 1313988.640561;
p(5) = -1035733.457595;
p(6) = 553311.967193;
p(7) = -202822.261894;
p(8) = 50352.652730;
p(9) = -8096.144837;
p(10) = 756.295117;
p(11) = -29.368304;

%Calculate K
ngap = gap / lambda_u;
k = exp(polyval(p, ngap));

%Done
