title: Taylor Series Sorting Exponents
body: <p>I have a MATLAB code that generates the exponent of general Taylor series of a 3-variable function f(x, y, z). In the example below, I am calculating the 3rd order Taylor series.</p>
  
  <pre><code>order = 3;
  nTuple = 3;
  allExponents = [];
  for n = 1 : order
      [~,x] = nsumk(nTuple, n); % nsumk can be downloaded from: https://www.mathworks.com/matlabcentral/fileexchange/28340-nsumk
      allExponents = [allExponents; x]
  end
  </code></pre>
  
  <p>The function generates the following coefficients:</p>
  
  <pre><code>0     0     1   % This means z with exponent 1; x and y with zero exponent.
  0     1     0   % This means y with exponent 1; x and z with zero exponent.
  1     0     0   % This means x with exponent 1; y and z with zero exponent.
  0     0     2
  0     1     1
  0     2     0
  1     0     1
  1     1     0
  2     0     0
  0     0     3
  0     1     2
  0     2     1   % This means x with exponent 0, y with exponent 2 and z with exponent 1, i,e, y^2*z
  0     3     0
  1     0     2
  1     1     1
  1     2     0
  2     0     1
  2     1     0   % This means x with exponent 2 and y with exponent 1 and z with exponent 0, i,e, x^2*y
  3     0     0
  </code></pre>
  
  <p>How can I sort them in the following form (the empty line between them is for clarity):</p>
  
  <pre><code>1     0     0    % x
  0     1     0    % y
  0     0     1    % z
  
  2     0     0    % x^2
  0     2     0    % y^2
  0     0     2    % z^2
  
  3     0     0    % x^3
  0     3     0    % y^3
  0     0     3    % z^3
  
  1     1     0    % x*y
  1     0     1    % x*z
  0     1     1    % y*z
  
  
  1     2     0    % x*y^2
  1     0     2    % x*z^2
  0     1     2    % y*z^2
  
  2     1     0    % x^2*y
  2     0     1    % x^2*z
  0     2     1    % y^2*z
  
  1     1     1    % x*y*z
  </code></pre>
  
  <p>Update: 
  Ordering is as follows:</p>
  
  <p>First x^n, y^n, z^n, where n is from 1 to the order of the Taylor series, in this particular example 3. </p>
  
  <p>Then, the cross multiplication of each two variable whose exponents add to 2, e.g, xy, xz, and yz. </p>
  
  <p>Then the cross multiplication of each two variables whose exponents adds to 3 with the first variable having exponent 1, i.e., xy^2, xz^2, yz^2. </p>
  
  <p>Then the cross multiplication of each two variables whose exponents add to 3 with the fist variable having exponent 2, i.e., x^2y, x^2z, y^2z.</p>
  
  <p>Lastly, the multiplication of all three variables whose exponents add to 3, i.e., xyz.</p>