function [x] = cbe101_inclass_material_balance_w_stoich(mdot1, xa1, xb2, rho2, vdot2, mwa, mwb, mwnr)
    % Solution of CBE 101 'Exercise: Species Material Balance with Formation or
    % Consumption'
    if nargin == 0
        mdot1 = 100;  % kg/hr
        xa1   = 0.7;  % ND
        xb2   = 0.3;  % ND
        rho2  = 1.1;  % kg/l
        vdot2 = 50;   % l/hr
        mwa   = 40;   % kg/kgmol
        mwb   = 30;   % kg/kgmol
        mwnr  = 18;   % kg/kgmol
    end
    
    % the coefficient matrix
    %    na1    na3    ra    nb2    rb    rc     nc3     nnr1    nnr2    nnr3
    A = [1      -1     -1     0      0     0      0      0        0       0
         0       0      0     1     -1     0      0      0        0       0
         0       0      0     0      0     1     -1      0        0       0
         0       0      0     0      0     0      0      1        1      -1
         0       0    -3/2.   0      1     0      0      0        0       0
         0       0    -1/2.   0      0     1      0      0        0       0
         1       0      0     0      0     0      0      0        0       0
         0       0      0     1      0     0      0      0        0       0
         0       0      0     0      0     0      0      1        0       0
         0       0      0     0      0     0      0      0        1       0];

    % the right-hand side vector
    b = [0
         0
         0
         0
         0
         0
         (xa1*mdot1)/mwa
         (xb2*rho2*vdot2)/mwb
         (1-xa1)*mdot1/mwnr
         (1-xb2)*rho2*vdot2/mwnr];
    
    x = A\b;
end