Chapter 19. Extending JMathLib

Table of Contents

m Files
External Functions

There are two ways to add add extra functions to the JMathLib. These are:

1) m files

2) External Functions

m Files

M files are script files written in the JMathLib language.

  
function A = perms (v)
  v = v(:);
  n = length (v);
  if (n == 1)
    A = v;
  else
    B = perms (v(1:n-1));
    Bidx = 1:size (B, 1);
    A = v(n) * ones (prod (2:n), n);
    A(Bidx,1:n-1) = B;
    k = size (B, 1);
    for x = n-1:-1:2
      A(k+Bidx,1:x-1) = B(Bidx,1:x-1);
      A(k+Bidx,x+1:n) = B(Bidx,x:n-1);
      k = k + size (B, 1);
    endfor
    A(k+Bidx,2:n) = B;
  endif
endfunction