bugGNU Octave - Bugs: bug #52673, fplot gives error for fplot(@(x)...

 
 

bug #52673: fplot gives error for fplot(@(x) 0, [-2,2])

Submitter:  None
Submitted:  Fri 15 Dec 2017 11:38:05 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  3 - Low Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  omer Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.1
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 15 Dec 2017 05:22:50 PM UTC, comment #2: 

Matlab itself, I believe, used to be strict about requiring a vectorized function.  At the bottom of their help they recommend, that for best performance, the function be vectorized and use element-by-element operators. 

I've marked this as a low priority since the documentation states what the expected input is.  Obvious workarounds are


fcn = @(x) 0 * x;
fcn = @(x) zeros (size (x));


which are both vectorized.

And as you also note, this happens to be a peculiarity of '0'.  There is already code that handles a constant value function which is non-zero like '5'.

It wasn't that hard to code a solution so I did that on the development branch of Octave in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/3cd47be4fcbe).  Octave now warns, as Matlab does, when the function is not vectorized but otherwise proceeds to create the plot.  I also added BIST tests to catch this example.

Since this is just an m-file, you can grab the code from Mercurial to see the fix.  Otherwise it will be part of the 4.4.0 release (no scheduled date for this yet).

Rik <rik5>
Group administrator
Fri 15 Dec 2017 12:46:57 PM UTC, comment #1: 

Thank you for your report.  Please consider the programming notes of fplot:


fplot requires that the function accept and return a vector argument. Consider this when writing user-defined functions and use .*, ./, etc. See the function vectorize for potentially converting inline or anonymous functions to vectorized versions.


https://www.gnu.org/software/octave/doc/interpreter/XREFfplot

So in general the function fplot was called with an improper function.

Matlab R2017b also throws a bunch of warnings before finally generating the desired plot.


Warning: Function behaves unexpectedly on array inputs. To improve
performance, properly vectorize your function to return an output with the
same size and shape as the input arguments.
> In matlab.graphics.function.FunctionLine>getFunction
  In matlab.graphics.function.FunctionLine/updateFunction
  In matlab.graphics.function.FunctionLine/set.Function_I
  In matlab.graphics.function.FunctionLine/set.Function
  In matlab.graphics.function.FunctionLine
  In fplot>singleFplot (line 232)
  In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 191)
  In fplot>vectorizeFplot (line 191)
  In fplot (line 161)


Thus I declare this item as Matlab compatibility problem.

Kai Torben Ohlhus <siko1056>
Group Member
Fri 15 Dec 2017 11:38:05 AM UTC, original submission:  

fplot function gives error for the function handler that returns constant 0. The problem is not occur with different constants.


fplot(@(x) 0, [-2, 2])
error: 'fcn_transpose' undefined near line 180 column 9
error: called from
    fplot at line 180 column 5


The fplot is okey with the


fplot(@(x) 0*x, [-2, 2])


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by siko1056 (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-12-15 rik5 Priority5 - Normal 3 - Low
        StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2017-12-15 siko1056 Item GroupUnexpected Error or Warning Matlab Compatibility
        StatusNone Confirmed
        Operating SystemMicrosoft Windows Any

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code