bugGNU Octave - Bugs: bug #55134, fplot failing on non-vectorized...

 
 

bug #55134: fplot failing on non-vectorized function

Submitter:  None
Submitted:  Thu 29 Nov 2018 07:47:12 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Stuart Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.4.1
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 03 Dec 2018 04:58:49 PM UTC, comment #4: 

Okay, thanks for testing.  The change I made works for both the original and modified versions of findX1 so I think we can call this report finished.

Rik <rik5>
Group administrator
Mon 03 Dec 2018 03:19:20 PM UTC, comment #3: 

Thanks for the fast response.


The result of running new_tst_fplot.m in MATLAB is the following warning and the two figures which are drawn correctly.

run('D:\School\MATLAB\new_tst_fplot.m')
For K=0: x=-0.247, y=-1.029, z=2.294
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 237)
  In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 192)
  In fplot>vectorizeFplot (line 192)
  In fplot (line 162)
  In new_tst_fplot (line 6)
  In run (line 91)


Anonymous
Fri 30 Nov 2018 01:10:12 AM UTC, comment #2: 

I pushed a fix to the development branch (https://hg.savannah.gnu.org/hgweb/octave/rev/46757ec0bac2).  I'd still like to know the answers to my questions in comment #1 when you have time.

This will be part of the 5.0 release due out near the end of the year.  In the meantime, I'm attaching the fplot.m file to this bug report.  You can just copy it in to your distribution to see the fix.

(file #45557)

Rik <rik5>
Group administrator
Thu 29 Nov 2018 09:35:47 PM UTC, comment #1: 

I'm very surprised that Matlab handles this, but I suppose they must have written a lot of input validation.

The trouble is not that your original function is not-vectorized, but that the subfunctions aren't.

The line


fplot(@findX1, [0 12]);


tries to plot the function findX1


function [x1] = findX1(K)
    % FINDX1 Finds the first element of the vector x for a given K
    % Inputs
    %   K - a constant
    % Outputs
    %   x1 - the first element of x
    x = findXall(K);
    x1 = x(1);

end


, but this function depends on findXall


function [x] = findXall(K)
    % FINDXALL Finds the vector x for a given K
    % Inputs
    %   K - a constant
    % Outputs
    %   x - a vector
    A = [5-K -2 4;
         -5 4+K 3;
         5 2 1+K];

    b = [10; 4; -1];

    x = A\b;

end


You can see that the construction of the matrix A is going to fail if K is not a scalar constant or a row vector.  Can you modify testfplot.m so that you take the transpose of K in the construction of A and then re-run it under Matlab?

Here is the new function I would like tested.


function [x] = findXall(K)
    % FINDXALL Finds the vector x for a given K
    % Inputs
    %   K - a constant
    % Outputs
    %   x - a vector
    A = [5-K' -2 4;
         -5 4+K' 3;
         5 2 1+K'];

    b = [10; 4; -1];

    x = A\b;

end


I made that change and have uploaded the file as new_tst_fplot.m.  With this change, Octave runs fine.  I'm attaching the plot which you can also verify looks more or less like the one from Matlab.



file #45556)

Rik <rik5>
Group administrator
Thu 29 Nov 2018 07:47:12 PM UTC, original submission:  

The attached code (for a school assignment) runs fine in Matlab but fails on the fplot line with

error: horizontal dimensions mismatch (5x1 vs 1x1)

The help file and bug#52673 both indicate that non-vectorized functions should work, if slower. I seem to have found an edge case.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #45557:  fplot.m added by rik5 (8KiB - text/x-matlab)
file #45555:  fplot.png added by rik5 (17KiB - image/png)
file #45556:  new_tst_fplot.m added by rik5 (865B - text/x-matlab)
file #45554:  testfplot.m added by None (893B - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by None (Submitted the item)
  •  

    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 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-11-30 rik5 Attached File- Added fplot.m, #45557
        StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2018-11-29 rik5 Attached File- Added fplot.png, #45555
        Attached File- Added new_tst_fplot.m, #45556
        StatusNone Need Info
    2018-11-29 None Attached File- Added testfplot.m, #45554

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code