function f = staging2(m_payload,k,Isp,deltaV,fif);
g = 9.81;                   %gravitational constant


m_L = zeros(1,k);                   %payload mass
m_Li = zeros(1,k);                  %payload mass for iteration
m_L(1) = m_payload;                       %seeding the payload array

m_i = zeros(1,k);                   %fueled mass
m_f = zeros(1,k);                   %burnout mass
m_fia = zeros(1,k);                  %burnout mass for iteration
m_fib = zeros(1,k);                  %second burnout iteration array
m_fib(1) = m_L(1);                  %seeding second burnout array

m_p = zeros(1,k);                   %propellant mass
m_pi = zeros(1,k);                   %propllant mass array for iterations
m_inf = zeros(1,k);                   %infrastructure mass

disp('Beginning Calculations...')

for i = 1:k
    m_Li(i) = m_L(i);                                   %give payload iteration array a starting point
    m_i(i) = m_Li(i)*exp(deltaV(i)/(g*Isp(i)));         %calculation of stage ignition mass
    m_p(i) = m_i(i) - m_Li(i);                          %calculation of propellant mass
    m_inf(i) = fif(i)*m_p(i);                           %calculation of infrastructure to support propellant mass
    m_fib(i) = m_L(i) + m_inf(i);                         %calculation of burnout mass
    while abs(m_fib(i) - m_Li(i)) > 1e-5               %open loop, 
        %compares the value of the old burnout mass to new burnout mass
        m_Li(i) = m_fib(i);                             %set new iterator payload mass
        m_i(i) = m_Li(i)*exp(deltaV(i)/(g*Isp(i)));        %calculate new ignition mass
        m_p(i) = m_i(i) - m_Li(i);                      %calculate new propellant mass
        m_inf(i) = fif(i)*m_p(i);                       %calculate new infrastructure mass
        m_fib(i) = m_L(i) + m_inf(i);                   %calculate new burnout mass
    end
    m_L(i+1) =  m_i(i);
        %set next stage's payload equal to current stage's ignition mass
        %only runs once current stage settles on a value
    m_f(i) = m_fib(i);
        %dump iterator burnout value into burnout collector
end


disp('By stage, delta-V  =')
disp(deltaV)
disp('.  .  . , Isp =')
disp(Isp)
disp('.  .  . , F.I.F. =')
disp(fif)
disp('.  .  . , Payload Mass =')
disp(m_L(1,1:3))
disp('.  .  . , Burnout Mass =')
disp(m_f)
disp('.  .  . , Ignition Mass =')
disp(m_i)