%**************************************************************************
%This function calculates By(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:
%by, By(y0, z)  (T)
%
%Zachary Wolf, 11/11/09

function [by] = field_calc_calc_by(bn, k_u, y0, z)

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

%Done
