# GenGellMann

 Other toolboxes required GenGellMann Produces a generalized Gell-Mann operator none GellMannGenPauliPauli Special states, vectors, and operators

GenGellMann is a function that produces generalized Gell-Mann matrices. That is, it produces Hermitian matrices that form a traceless orthogonal basis for the space of $d \times d$ complex matrices.

## Syntax

• G = GenGellMann(IND1,IND2,DIM)
• G = GenGellMann(IND1,IND2,DIM,SP)

## Argument descriptions

• IND1 and IND2: Integers between 0 and DIM-1, inclusive. If IND1 == IND2 then G will be diagonal. If IND1 < IND2 then G will be real and have exactly 2 nonzero entries. If IND1 > IND2 then G will be imaginary and have exactly 2 nonzero entries.
• DIM: The size of the output matrix.
• SP (optional, default 0): A flag (either 1 or 0) indicating that the generalized Gell-Mann matrix produced should or should not be sparse.

## Examples

### Gives the Pauli operators when DIM = 2

>> GenGellMann(0,0,2) % identity

ans =

1     0
0     1

>> GenGellMann(0,1,2) % Pauli X

ans =

0     1
1     0

>> GenGellMann(1,0,2) % Pauli Y

ans =

0.0000 + 0.0000i   0.0000 - 1.0000i
0.0000 + 1.0000i   0.0000 + 0.0000i

>> GenGellMann(1,1,2) % Pauli Z

ans =

1     0
0    -1

### Gives the Gell-Mann operators when DIM = 3

>> GenGellMann(0,1,3)

ans =

0     1     0
1     0     0
0     0     0

>> GenGellMann(0,2,3)

ans =

0     0     1
0     0     0
1     0     0

>> GenGellMann(2,2,3)

ans =

0.5774         0         0
0    0.5774         0
0         0   -1.1547

### In Higher Dimensions

Generalized Gell-Mann matrices can be generated in arbitrary dimensions. It is recommended that you set SP = 1 if DIM is large in order to save memory.

>> GenGellMann(2,3,4)

ans =

0     0     0     0
0     0     0     0
0     0     0     1
0     0     1     0

>> GenGellMann(205,34,500,1) % a 500-by-500 sparse generalized Gell-Mann matrix

ans =

(206,35)     0.0000 + 1.0000i
(35,206)    0.0000 - 1.0000i

## Source code

Click on "expand" to the right to view the MATLAB source code for this function.

1. %%  GENGELLMANN    Produces a generalized Gell-Mann operator
2. %   This function has three required arguments:
3. %     IND1 (a nonnegative integer from 0 to DIM-1 inclusive)
4. %     IND2 (a nonnegative integer from 0 to DIM-1 inclusive)
5. %     DIM (a positive integer indicating the dimension)
6. %
7. %   G = GenGellMann(IND1,IND2,DIM) is a DIM-by-DIM Hermitian operator.
8. %   These matrices span the entire space of DIM-by-DIM matrices as IND1 and
9. %   IND2 range from 0 to DIM-1, inclusive, and they generalize the Pauli
10. %   operators when DIM = 2 and the Gell-Mann operators when DIM = 3.
11. %
12. %   This function has one optional argument:
13. %     SP (default 0)
14. %
15. %   G = GenGellMann(IND1,IND2,DIM,SP) is as above, with sparsity of the
16. %   output determined by the value of SP. If SP = 0 then the output will be
17. %   full, if SP = 1 then the output will be sparse.
18. %
19. %   URL: http://www.qetlab.com/GenGellMann
20. 
21. %   requires: opt_args.m
22. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
23. %   package: QETLAB
24. %   last updated: December 18, 2013
25. 
26. function g = GenGellMann(ind1,ind2,dim,varargin)
27. 
28. % set optional argument defaults: sp=0
29. [sp] = opt_args({ 0 },varargin{:});
30. 
31. if(ind1 == ind2)
32.     if(ind1 == 0)
33.         g = speye(dim);
34.     else
35.         g = sqrt(2/(ind1*(ind1+1)))*spdiags([ones(ind1,1);-ind1;zeros(dim-ind1-1,1)],0,dim,dim);
36.     end
37. else
38.     E = sparse(dim,dim);
39.     E(ind1+1,ind2+1) = 1;
40.     if(ind1 < ind2)
41.         g = E + E';
42.     else
43.         g = 1i*E - 1i*E';
44.     end
45. end
46. 
47. if(~sp)
48.     g = full(g);
49. end