octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #34365] pascal(n,2) returns different permutat


From: Vanya Sergeev
Subject: [Octave-bug-tracker] [bug #34365] pascal(n,2) returns different permutation than ML; pascal() for n=0 inaccurately returns [1]
Date: Fri, 23 Sep 2011 09:21:00 +0000
User-agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1

URL:
  <http://savannah.gnu.org/bugs/?34365>

                 Summary: pascal(n,2) returns different permutation than ML;
pascal() for n=0 inaccurately returns [1]
                 Project: GNU Octave
            Submitted by: vsergeev
            Submitted on: Fri 23 Sep 2011 09:20:59 AM GMT
                Category: Libraries
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: dev
        Operating System: Any

    _______________________________________________________

Details:

ML's pascal(n,2) returns the horizontal permutation of pascal(n,1)', whereas
Octave's pascal(n,2) returns the vertical permutation of pascal(n,1)'. They're
both valid permutations of pascal(n,1)' in that pascal(n,2)^3 = eye(n), but
using the same permutation as ML might be warranted for compatibility
purposes.

Octave also does not handle the n=0 case correctly, it returns a 1x1 matrix
[1] for pascal(0) and pascal(0,1), and errors out for pascal(0,2). ML returns
the 0x0 empty matrix for pascal(n), 0x1 empty matrix for pascal(n,1), and 1x0
empty matrix for pascal(n,2).

MATLAB's pascal():

>> pascal(3,1)

ans =

     1     0     0
     1    -1     0
     1    -2     1

>> pascal(3,1)'

ans =

     1     1     1
     0    -1    -2
     0     0     1

>> pascal(3,2)

ans =

     1     1     1
    -2    -1     0
     1     0     0

>> pascal(4,2)

ans =

    -1    -1    -1    -1
     3     2     1     0
    -3    -1     0     0
     1     0     0     0

>> pascal(0)

ans =

     []

>> pascal(0,1)

ans =

   Empty matrix: 0-by-1

>> pascal(0,2)

ans =

   Empty matrix: 1-by-0

>> 


Octave's pascal():

octave:162> pascal(3,1)
ans =

   1   0   0
   1  -1   0
   1  -2   1

octave:163> pascal(3,1)'
ans =

   1   1   1
   0  -1  -2
   0   0   1

octave:164> pascal(3,2)
ans =

   0   0  -1
   0  -1   2
  -1  -1   1

octave:165> pascal(4,2)
ans =

  -0  -0  -0  -1
  -0  -0  -1   3
  -0   1   2  -3
   1   1   1  -1 

octave:166> pascal(0)
ans =  1
octave:167> pascal(0,1)
ans =  1
octave:168> pascal(0,2)
error: pascal: subscript indices must be either positive integers or logicals
error: called from:
error:   /usr/share/octave/3.4.2/m/special-matrix/pascal.m at line 75, column
17
octave:169> 


Attached is hg patch to scripts/special-matrix/pascal.m for improved ML
compatibility with pascal(), as well as a fix for the n=0 case.

The patched pascal() octave output:

octave:1> pascal(3,2)
ans =

   1   1   1
  -2  -1   0
   1   0   0

octave:2> pascal(4,2)
ans =

  -1  -1  -1  -1
   3   2   1  -0
  -3  -1  -0  -0
   1  -0  -0  -0

octave:3> pascal(0)
ans = [](0x0)
octave:4> pascal(0,1)
ans = [](0x0)
octave:5> pascal(0,2)
ans = [](0x0)
octave:6> 


For simplicity, I didn't make the modifications to reflect ML's dimensions of
the empty matrix with pascal(0,1) and pascal(0,2), but this can probably be
easily added if it's necessary.

~vsergeev



    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Fri 23 Sep 2011 09:20:59 AM GMT  Name: pascal.diff  Size: 1kB   By:
vsergeev
hg changeset patch for pascal.m
<http://savannah.gnu.org/bugs/download.php?file_id=24017>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?34365>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]