Perm inv

From QETLAB
Jump to: navigation, search
perm_inv
Computes the inverse of a permutation

Other toolboxes required none
Related functions perm_sign
Function category Helper functions
This is a helper function that only exists to aid other functions in QETLAB. If you are an end-user of QETLAB, you likely will never have a reason to use this function.

perm_inv is a function that computes the inverse of a permutation.

Syntax

  • PI = perm_inv(PERM)

Argument descriptions

  • PERM: A vector containing a permutation of the integers 1, 2, ..., n.

Examples

Small examples

The identity permutation is its own inverse:

>> perm_inv(1:4)
 
ans =
 
     1     2     3     4

To compute the inverse of the permutation on this MathWorld page, we can use the following line of code:

>> perm_inv([3,8,5,10,9,4,6,1,7,2])
 
ans =
 
     8    10     1     6     3     7     9     2     5     4

Source code

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

  1. %%  PERM_INV    Computes the inverse of a permutation
  2. %   This function has one required argument:
  3. %     PERM: a permutation vector
  4. %
  5. %   PI = perm_inv(PERM) is the inverse permutation of PERM.
  6. %
  7. %   URL: http://www.qetlab.com/perm_inv
  8.  
  9. %   requires: nothing
  10. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
  11. %   package: QETLAB
  12. %   last updated: November 28, 2012
  13.  
  14. function res = perm_inv(perm)
  15.  
  16. [~,res] = sort(perm);