bugGNU Octave - Bugs: bug #38961, fplot needs adaptive scaling...

 
 

bug #38961: fplot needs adaptive scaling algorithm

Submitter:  None
Submitted:  Fri 10 May 2013 05:15:31 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Confirmed Assigned to:  None
Originator Name:  Mariusz Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 19 Apr 2023 03:13:48 AM UTC, comment #7: 

assuming the y axis limits are indicative of the problem, the fplot (@tan, [-2,2]) still gives yaxis limits of +/-300000 in Octave 8.2.0

Nicholas Jankowski <nrjank>
Group Member
Sun 20 Nov 2016 10:26:30 PM UTC, comment #6: 

This (remaining) issue is still present in Octave 4.2.0.

(The code line from comment #5 still gives me y-axis limits of +-300000.)

Hartmut <hardy>
Thu 11 Jul 2013 04:32:20 PM UTC, comment #5: 

I overhauled fplot in this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/b34202b24212).  I upgraded it to be more Matlab compatible and I added an additional stopping condition to detect when the algorithm is failing.  This works for functions which end up having a relative tolerance that won't converge because the function value at 0 is near 0.  However, the real long-term fix is to add an adapative scaling algorithm of the sort used in the quadrature routines.  Basically, the current algorithm is no good if the function contains discontinuities.  Try


fplot (@tan, [-2,2])


to see just how bad.

Rik <rik5>
Group administrator
Thu 16 May 2013 02:26:06 PM UTC, comment #4: 

I've changed the category as this also occurs for OpenGL plotting.

I tried the example in Matlab R2013a.  Matlab's fplot() limits the number of points to 111 for this example to 111.


fplot ('x^2*sin(x)+1', [-2, 2]);
size (get (get (gca, 'children'), 'xdata'))
ans =  1   111



figure (1)
fplot ('x^2*sin(x)+0', [-2, 2]);
size (get (get (gca, 'children'), 'xdata'))
ans =  1   111


I've included two more examples for reference.


fplot ('sin(x)', [-2, 2]);
size (get (get (gca, 'children'), 'xdata'))
ans =  1   179



fplot ('x', [-2, 2]);
size (get (get (gca, 'children'), 'xdata'))
ans =  1   10



fplot ('1/x', [-2, 2]);
size (get (get (gca, 'children'), 'xdata'))
ans =  1   176


I can run additional examples if it is helpful.

Ben Abbott <bpabbott>
Group Member
Fri 10 May 2013 11:34:02 PM UTC, comment #3: 

Ok, I looked at this a little deeper. The default tolerance is the same in all cases, 2e-3. Fplot iteratively interpolates the given function over increasing ranges of x until the maximum error falls below that threshold. Your particular function simply never converges, at least using the calculation of error in there now.

I think convergence is failing on certain functions that have very small values near the origin where interpolation is slightly off, such that small absolute errors become large relative errors. Besides your function "x^2 * sin(x)", another example function that doesn't converge is "x^2 + x^4". Another is "(exp(x)-1)^2".

It could be argued that the method for calculating convergence could be improved to fix this problem. Needs input from someone with a stronger mathematical background than mine.

Mike Miller <mtmiller>
Group Member
Fri 10 May 2013 09:31:41 PM UTC, comment #2: 

Why does it use the default tolerance for the first but not the second? It shouldn't be dependent on the function. If it is, it shouldn't change by orders of magnitude by simply subtracting 1 from the function I'm plotting.

I'm creating an example for a tutorial and I'm wondering how to explain the unexpected behavior.

Anonymous
Fri 10 May 2013 05:58:39 PM UTC, comment #1: 

Confirmed, but no I don't think it's a bug. The third argument to fplot gives you control over how many points or how accurate the plot should be made. Your second plot is slow because of the particular function you are evaluating and the default tolerance of fplot, not simply because something was changed. If you limit the plot to a fixed number of points you should see no change in speed.


octave:1> fplot ("x^2*sin(x)+1", [-2, 2]);
octave:2> size (get (get (gca, "children"), "xdata"))
ans =
      1   1793
octave:3> fplot ("x^2*sin(x)+0", [-2, 2]);
octave:4> size (get (get (gca, "children"), "xdata"))
ans =
         1   1835009
octave:5> fplot ("x^2*sin(x)+1", [-2, 2], 2000), tic, print(1, "a.png","-dpng"), toc
Elapsed time is 0.56231612 seconds.
octave:6> fplot ("x^2*sin(x)+0", [-2, 2], 2000), tic, print(1, "a.png","-dpng"), toc
Elapsed time is 0.53061102 seconds.


Does that address the problem?

Mike Miller <mtmiller>
Group Member
Fri 10 May 2013 05:15:31 PM UTC, original submission:  

print takes a very long time when changing the plot in a minor way.

octave:1> fplot('x^2*sin(x)+1',[-2 2]),tic,print(1, "a.png","-dpng"),toc
Elapsed time is 0.707911 seconds.

octave:2> fplot('x^2*sin(x)+0',[-2 2]),tic,print(1, "b.png","-dpng"),toc
Elapsed time is 14.3234 seconds.

I'm not complaining, I just think it's very very odd. I get this behavior consistently. Can anyone offer an explanation if this isn't a bug?

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 nrjank (Posted a comment)
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by bpabbott (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -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 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-04-19 nrjank StatusPostponed Confirmed
    2016-11-16 mtmiller StatusConfirmed Postponed
        Release3.6.3 dev
    2013-07-11 rik5 Item GroupPerformance Inaccurate Result
        StatusNeed Info Confirmed
        Summaryprint freezes when printing certain fplots fplot needs adaptive scaling algorithm
    2013-05-16 bpabbott CategoryPlotting with gnuplot Plotting
    2013-05-10 mtmiller Item GroupSegfault, Bus Error, etc. Performance
        Operating SystemMac OS Any
    2013-05-10 mtmiller StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code