bugGNU Octave - Bugs: bug #49449, odeplot is not fully Matlab...

 
 

bug #49449: odeplot is not fully Matlab compatible

Submitter:  Sebastian <sschoeps>
Submitted:  Wed 26 Oct 2016 03:44:04 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 28 Oct 2016 09:32:59 AM UTC, comment #7: 

I made a new checkout and yes, everything is working now as in Matlab. Thanks!

Sebastian <sschoeps>
Fri 28 Oct 2016 12:59:07 AM UTC, comment #6: 

The number of columns is equal to the number of equations being solved.  You called init with a single column so only one equation was expected rather than the 11 in the expression [0:10].

Try this which has 3 equations and 5 timesteps.


odeplot ([0, 10], [1 2 3], 'init');
odeplot ([1;2;3;4;5], rand (3,5), []);


That still might fail in Octave unless you are at least up to 22683:340e37fd3c20.

I fixed the typo in the documentation on the stable branch (http://hg.savannah.gnu.org/hgweb/octave/rev/ce0f54b63923).

Rik <rik5>
Group administrator
Thu 27 Oct 2016 10:40:11 PM UTC, comment #5: 


>So they are clear that when there are multiple times, y is a matrix with numel(t) rows and >with the number of columns equal to the number of equations being solved.

Are you sure? Matlab throws an error when using your description:

>> odeplot([0 10]',1,'init');
>> odeplot([0:10]',0:10,[]);

Error using odeplot (line 63)
Error updating the ODEPLOT window. Solution data may have been corrupted. Index exceeds matrix dimensions.

Another thing that is simple to cure: there is a typo in the docs that I noticed and had fixed: odeplot ([], [], "end") -> odeplot ([], [], "done")

Seb.

Sebastian <sschoeps>
Wed 26 Oct 2016 11:12:40 PM UTC, comment #4: 

plot() isn't recommended, even in Matlab, for user-created OutputFcns.  See https://www.mathworks.com/matlabcentral/newsreader/view_thread/296870.

The documentation for odeset (http://www.mathworks.com/help/matlab/ref/odeset.html) and the OutputFcn property says that


The solver calls status = myOutputFcn(t,y,[]) after each integration step for which output is requested. t contains points where output was generated during the step, and y is the numerical solution at the points in t. If t is a vector, then the ith column of y corresponds to the ith element of t.


So they are clear that when there are multiple times, y is a matrix with numel(t) rows and with the number of columns equal to the number of equations being solved.

It's easy enough to use all the points given as input rather than the first.  I made that change on the development branch here (http://hg.savannah.gnu.org/hgweb/octave/rev/7c45d565d1b7).  Interestingly, this gets us bug-for-bug compatible with Matlab as there is the funny line running back to the origin.  I also changed the marker to 'o' from '.' since that is what I see in the pictures you posted.  It is 31% slower to use that marker, but those are the breaks.



Rik <rik5>
Group administrator
Wed 26 Oct 2016 06:27:16 PM UTC, comment #3: 

Sorry, my explanation was insufficient and two things got mixed up:

1. the current octave implementation of odeplot is not fully Matlab compatible. It only plots the last entry of the vectors given and Octave cares whether you supply row or column vectors. However, it's working in most cases but probably not if we implement "refine" in odeXY.

I have executed the following lines with Matlab, Octave with and without patch  (see figures attached):
odeplot([0 10],[0;0],'init');
odeplot([0:10],[(0:10);(0:10).^2],[]);
odeplot([0:10],2*[(0:10);(0:10).^2],[]);

2. I made a new version that is slower but this is no surprise: it always plots the whole data (as Matlab does). Matlab seems to store the data persistently in odeplot and to concatenate the vectors in each call of odeplot. This can be seen in the attached figure "matlab.png". There is a straight line from (10,100) to (0,0). My implementation avoids this by using "hold on" and "hold off", so I am more memory efficient but not Matlab-bug-compatible.


Sebastian <sschoeps>
Wed 26 Oct 2016 05:34:11 PM UTC, comment #2: 

Using plot is slow.  I've attached the script I used for benchmarking as tst_odeplot.m.

Benchmark results:

Current fcn: 1.5 seconds
New fcn    : 2.1 seconds

I don't see a reason to switch as most machines have gobs of memory.  Even a system with 100 coupled ODEs evaluated at 1000 points consumes just 800 kB of memory.

However, if there is a visual difference we could adjust that.  Octave is currently using the dot marker '.' and connecting them with a solid line '-'.  Could you run tst_odeplot.m in Matlab and then print out the resulting figure as a png file and attach it to this bug report?

(file #38818)

Rik <rik5>
Group administrator
Wed 26 Oct 2016 03:49:50 PM UTC, comment #1: 

I don't say we need to fix this urgently before 4.2.0.

Sebastian <sschoeps>
Wed 26 Oct 2016 03:44:04 PM UTC, original submission:  

Jacopo and I have realized that odeplot is not fully Matlab compatible. Currently, it only adds a single point to the plot per call. I attach a new file that exploits "hold on" and hold off" such that there is no need to store data persistently (as Matlab seems to do it, too).

Sebastian


Sebastian <sschoeps>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #38819:  matlab.png added by sschoeps (101KiB - image/png)
file #38820:  octave_patched.png added by sschoeps (115KiB - image/png)
file #38821:  octave_current.png added by sschoeps (77KiB - image/png)
file #38818:  tst_odeplot.m added by rik5 (155B - d2l/unknowntype)
file #38817:  odeplot.m added by sschoeps (4KiB - application/octet-stream)

 

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 sschoeps
  • -email is unavailable- added by sschoeps
  • -email is unavailable- added by sschoeps (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 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-10-26 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
    2016-10-26 sschoeps Attached File- Added matlab.png, #38819
        Attached File- Added octave_patched.png, #38820
        Attached File- Added octave_current.png, #38821
    2016-10-26 rik5 Attached File- Added tst_odeplot.m, #38818
    2016-10-26 sschoeps Carbon-Copy- Added -email is unavailable-
        Carbon-Copy- Added -email is unavailable-
        Carbon-Copy- Added -email is unavailable-
    2016-10-26 sschoeps Attached File- Added odeplot.m, #38817

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code