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

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

[Octave-bug-tracker] [bug #51728] del2 fails on 1-D input with a vector


From: anonymous
Subject: [Octave-bug-tracker] [bug #51728] del2 fails on 1-D input with a vector as spacing
Date: Fri, 11 Aug 2017 07:04:58 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:54.0) Gecko/20100101 Firefox/54.0

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

                 Summary: del2 fails on 1-D input with a vector as spacing
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Fri 11 Aug 2017 11:04:56 AM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Unexpected Error
                  Status: None
             Assigned to: None
         Originator Name: Roger Jeurissen
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.0.0
        Operating System: GNU/Linux

    _______________________________________________________

Details:

According to the documentation, the discrete Laplacian of a 1-D array can be
calculated with del2, with non-uniform spacing. When I tried to use this,
octave threw an error:

error: del2: dimensionality mismatch in 1-th spacing vector

The following code reproduces the error:

x = linspace(-2*pi,2*pi);
U = cos(x);
L = 4*del2(U,x);


In Matlab, this does return a value without errors.

I suspect that this originates from line 73 of del2. There, ndims is used to
obtain the number of dimensions of the input array, and this value is stored
in the variable nd. However, ndims returns 2 for a 1-D array. What is needed
is the number of non-singleton dimensions:


nd = sum(size(M)>1);


However, this would break the functionality later on, because the for loops
run over the dimensions. To fix that, we can add the following lines after
line 73:


if(nd==1)
   M=M(:);
end


We should also add this line at the end:


if(nd==1)
   D=reshape(D,size(M));
end


As far as I can see right now, this should work. I tested this fix to check
that it solves the issue that i encountered, and it does. 






    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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