%**************************************************************************
%This function calculates Bz(z) from the field expansion coeffieients.
%
%Input:
%bn(1 to num_bn), field expansion coefficients
%k_u, undulator period parameter, 2 * pi / l_u (m)
%y0, y-position to calculate the field at (m)
%z, z-positions to calculate the field at (m)
%
%Output:
%bz, Bz(y0, z)  (T)
%
%Zachary Wolf, 11/11/09

function [bz] = field_calc_calc_bz(bn, k_u, y0, z)

%Field calculation
%by = Sum bn sin(nkz) cosh(nky)
%bz = Sum bn cos(nkz) sinh(nky)
bz = zeros(1, length(z));
for nn = 1 : length(bn)
    bz = bz + bn(nn) * cos(nn * k_u * z) * sinh(nn * k_u * y0);
end

%Done
