Recent

Author Topic: TFunctionSeries not updating y extent  (Read 6058 times)

wp

  • Hero Member
  • *****
  • Posts: 11916
TFunctionSeries not updating y extent
« on: September 06, 2012, 10:21:44 am »
I am experimenting with a math function plotter based upon TExpressionParser and TFuncSeries. Works fine, but what I found out is that the TFuncSeries does not update the vertical extent of the y axis. Am I missing something?

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TFunctionSeries not updating y extent
« Reply #1 on: September 06, 2012, 02:17:28 pm »
Use FuncSeries.Extent and DomainExclusions properties.

Automatic determination of function extent is quite hard.
Consider f(x)=1/x.
If I understand correctly, mathematical software uses symbolic calculation for that,
which is obviously out of scope for TAChart.

I guess I can add some heuristics (for example, setting "outer bounds" extent
and automatically shrinking it if all calculated values fit inside).

Similarly, user must currently set DomainExclusions by hand,
although it can be, to some extent, determined heuristically
(which would also fix your old issue about fit series incorrectly working with NaNs).

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TFunctionSeries not updating y extent
« Reply #2 on: September 06, 2012, 07:25:09 pm »
Quote
setting "outer bounds" extent and automatically shrinking it if all calculated values fit inside
Something like this would be fine.

Quote
user must currently set DomainExclusions by hand
To be honest I still have to dig into the details of DomainExclusions. If I understand correctly, this is a mechanism which prevents drawing of undefined function values, like the 1/x at x=0 that you mention, or log(x) for x <=0?

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TFunctionSeries not updating y extent
« Reply #3 on: September 18, 2012, 11:47:27 am »
Added TFuncSeries.ExtentAutoY property in r38730,
see "Auto Y extent" page in "func" demo since r38731.

Note that the property applies only if both Extent.UseXMin and Extent.UseXMax are true.

Additionally, if the function is not smooth, it is recommended to set UseYMin and UseXMax anyway. You can try to set Chart1.Extent.UseYMax = false and Chart1FuncSeries1.ExtentAutoY = true on the "Domain" page of the "func" demo to see what happens otherwise.

Quote
details of DomainExclusions. If I understand correctly, this is a mechanism which prevents drawing of undefined function values
Yes, exactly. You can also use it to arbitrarily split function domain into several disconnected parts.

What I talked about is that DomainExclusions might be automatically added for points where function returns NaN (or even raises an exception).

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TFunctionSeries not updating y extent
« Reply #4 on: September 18, 2012, 12:54:21 pm »
Quote
Added TFuncSeries.ExtentAutoY property in r38730
Thank you - I'll test it as soon as I can.

Quote
What I talked about is that DomainExclusions might be automatically added for points where function returns NaN
That's what I do not understand with DomainExclusions: when the function returns NaN then the line segment should not be drawn (as it is the case with TLineSeries), and that's the same effect as the DomainExclusion. I have to admit, though, that the exception handling of Lazarus seems to be a bit rough - I am getting nonrecoverable math exceptions (like divide by zero, or log of negative numbers) when the debugger is running; but when the application runs on its own the exceptions are nicely trapped. I'll try to find some systematics and post this issue separately.

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: TFunctionSeries not updating y extent
« Reply #5 on: September 18, 2012, 06:38:30 pm »
There are several differences between NaNs and DomainExclusions in functional series:
1) Currently DomainExclusions work, while NaNs do not
2) Automatically extracting domain from arbitrary function is unreliable -- this is quite similar to the reason I did not want to implement automatic extent. Finding discontinuity will be predicated on trying to calculate value inside of it, which may be unlikely, especially for single-point exclusions.
3) Once found, it is not entirely obvious what to do -- actual point of discontinuity is somewhere between current point and previously drawn one. Ideally, chart should use binary search to find it.
4) Raising exceptions is slow. So finding domain based on exceptions may be inefficient for functions like Log and Sqrt.

Nevertheless, all of the above is "just a matter of programming", so if it is required,
I'll consider implementing it.
Additionally, I have thought about adding discontinuity marks, but postponed it
until somebody needs them.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TFunctionSeries not updating y extent
« Reply #6 on: September 18, 2012, 10:29:49 pm »
Quote
Quote
Added TFuncSeries.ExtentAutoY property in r38730
Thank you - I'll test it as soon as I can.
Working perfectly - thanks again.

Quote
There are several differences between NaNs and DomainExclusions in functional series
Thanks for the explanation.

Quote
so if it is required, I'll consider implementing it
I'm not sure if I need it... My primary intention was to use this project in a tutorial on TFuncSeries, but it is getting quite complicated anyway (NaNs not working ideally, DomainExclusions difficult to handle with parsed functions), so maybe I'll look for another example.

 

TinyPortal © 2005-2018