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

 
 

bug #38961: fplot needs adaptive scaling algorithm

Submitted by:  None
Submitted on:  Fri 10 May 2013 05:15:31 PM UTC  
 
Category: PlottingSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Inaccurate Result
Status: ConfirmedAssigned to: None
Originator Name: MariuszOriginator Email: -unavailable-
Open/Closed: OpenRelease: 3.6.3
Operating System: Any

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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

to see just how bad.

Rik <rik5>
Project 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.

I've included two more examples for reference.

I can run additional examples if it is helpful.

Ben Abbott <bpabbott>
Project 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>
Project 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.

Does that address the problem?

Mike Miller <mtmiller>
Project 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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by rik5 (Posted a comment)
  • -unavailable- added by bpabbott (Posted a comment)
  • -unavailable- added by mtmiller (Posted a comment)
  • -unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 11 Jul 2013 04:32:20 PM UTCrik5Item GroupPerformance=>Inaccurate Result
      StatusNeed Info=>Confirmed
      Summaryprint freezes when printing certain fplots=>fplot needs adaptive scaling algorithm
    Thu 16 May 2013 02:26:06 PM UTCbpabbottCategoryPlotting with gnuplot=>Plotting
    Fri 10 May 2013 11:34:02 PM UTCmtmillerItem GroupCrash=>Performance
      Operating SystemMac OS=>Any
    Fri 10 May 2013 05:58:39 PM UTCmtmillerStatusNone=>Need Info

    Back to the top


    Powered by Savane 3.1-cleanup