[2D plot] Plot of points in piecewise functions

[2D plot] Plot of points in piecewise functions - Messages

#1 Posted: 11/20/2018 6:45:41 AM
Michał Janowski

Michał Janowski

1 likes in 7 posts.

Group: User

Hello!

I have a problem with simple equation. In case of my function, f(10) is equal to 5 but there is no "dot" of such value on the graph.
Please tell me how it should look like.

Where is the dot.sm (3 KiB) downloaded 43 time(s).

Where is the dot.jpg

Best regards.
Mroczak
#2 Posted: 11/20/2018 10:30:13 AM
Fridel Selitsky

Fridel Selitsky

520 likes in 451 posts.

Group: User

Just point x=10 must be drawn
#3 Posted: 11/20/2018 1:23:46 PM
Michał Janowski

Michał Janowski

1 likes in 7 posts.

Group: User

I think, that it is not proper solution. That "point" is already included in definition of the function, so why I should draw it manually. What in case, if the function is more complex and I don't know that there is such orphaned value in the middle of continous parts of function just from looking on the function definition. Your solution is correct in situation if we exactly know that there is such thing. It should be drawn on the graph somehow automatically, but it's not.

Best regards,
Mroczak
#4 Posted: 11/20/2018 1:41:01 PM
Arie

Arie

93 likes in 285 posts.

Group: User

I think the issue is the auto-generated range does not include the point x=10 exactly and therefore never reaches the point where f(x) = 5. Simply allowing for some error as I've done in the attached solves the problem for me. Where is the dot (1).sm (3 KiB) downloaded 34 time(s).

Another option, defining the range discretely.

Where is the dot discrete.sm (5 KiB) downloaded 39 time(s).
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#5 Posted: 11/20/2018 2:12:09 PM
Michał Janowski

Michał Janowski

1 likes in 7 posts.

Group: User

From your example it follows, that there is a problem on the level of logical operators - you had to manually insert error what should be done by choosing 'lower' and 'higher' instead of 'lower or equal' and 'higher or eqal'. It looks like, that in such function there is no difference between operators 'lower' and 'higher' vs 'lower or equal' and 'higher or equal'. For me, it should't work this way and it seems to be some kind of 'bug'. At least your idea works as problem workaround, but unfortunately it is still only workaround. Thank you for your answer!

Best regards,
Mroczak
#6 Posted: 11/20/2018 3:09:48 PM
Davide Carpi

Davide Carpi

1415 likes in 2872 posts.

Group: Moderator

Wrote

think the issue is the auto-generated range does not include the point x=10 exactly and therefore never reaches the point where f(x) = 5



That's part of "the point". The function has to be drawn on the canvas, thus it is calculated for each pixel, and each pixel correspond to a value that depends on the range (first and last values visible), and even on the number of pixels (the width of the canvas).

You can figure it easily placing a breakpoint in the plot placeholder and looking at the values of x.

2018-11-20 19_07_51-SMath Studio - [Where%20is%20the%20dot.sm_].png

You must be very lucky to hit exactly 10.000000000000000 (15 digits)
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#7 Posted: 11/20/2018 3:10:32 PM
frapuano

frapuano

13 likes in 115 posts.

Group: User

Peter,

the issue -in my modest opinion - is only on the plot side; your definition of the function and its discontinuity works fine and the value f(10) is evaluated correctly ..but plotting a function with discontinuity requires a discontinuity analyzer i.e. you need ( I mean the developer of the 2d Plot that I guess is Andrey ) to develop a module that find the discontinuities , analyze them and behaves accordingly ( these are at least of 3 different types for functions of one variable ) and this is not so easy to handle.
This remembers me 40 years ago when on a Sperry Univac I had to develop in fortran by myself something to plot correctly the angular patter of the radiation scattered when a laser beam is sent in a spray of fuel droplets, this produces at some particular angles rainmbows so discontinuities in the pattern that created many troubles to the offline plotter I were using at the time, took me a lot of effort ( and euristics ) to analyze and try to solve this issue.

Best regards

Franco
#8 Posted: 11/20/2018 4:14:02 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

I have a problem with simple equation. In case of my function, f(10) is equal to 5 but there is no "dot" of such value on the graph.
Please tell me how it should look like.


Your setup is not correct. Once in a while, undefined condition(s) do not reflect.
In very rare instances, it's the other way around, i.e: one of the condition must
be undefined wrt the algorithmic suite [typical => De Boor spline point].

Where is the dot discrete.sm (6 KiB) downloaded 49 time(s).

if_otherwise.PNG

#9 Posted: 11/20/2018 6:46:02 PM
Arie

Arie

93 likes in 285 posts.

Group: User

Wrote


the issue -in my modest opinion - is only on the plot side



Yes and no. You cannot really expect the program to know to evaluate/plot at a specific point for any arbitrary function. Additionally as shown in the figure below one can produce "incorrect" results by exploiting the fact that we're performing calculations on a discrete system.

It may seem like the plot "should" be able to detect an infinitesimal point at x=10, but what if we redefined it for x=pi or any arbitrary number. It becomes very difficult to find that single point discontinuity in the function.

I think in an instance like this, the user needs to either add some "fudge-factor" to the function or define the range manually to include the point(s) in question.
Untitled.png
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#10 Posted: 11/20/2018 7:56:45 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote

Wrote


the issue -in my modest opinion - is only on the plot side



Yes and no. You cannot really expect the program to know to evaluate/plot at a specific point for any arbitrary function.



Hi. Yes, you can. With the normal issues for symbolic or numeric manipulations. And as frapuano talk, in some moment we need to implement some code for handle singularities. As an example, maybe too much specific, but about finite jumps, you can see
https://en.smath.info/forum/yaf_postst14910_Round.aspx and the implementation of discontinuous plots in round.sm (69 KiB) downloaded 100 time(s).

Maple have following functions, but need readlib for the following two:

Clipboard03.gif

Clipboard01.gif

Also can use this option for plots:

Clipboard06.gif

Best regards.
Alvaro.
#11 Posted: 11/21/2018 1:29:12 AM
Arie

Arie

93 likes in 285 posts.

Group: User

Wrote



Maple have following functions, but need readlib for the following two:


Alvaro.



I see your point. I found a piecewise plotting example with removable discontinuity in maple here (need to scroll down).

A couple points to note. Generally, I don't think something like fdiscont would work for piecewise functions with single point discontinuities or perhaps even jump continuities. It mentions issues with these in the description.

I notice that both Maple and Matlab have "piecewise" functions. I assume that in those environments the "piecewise" functions may be an indicator to the "plot" function that specific conditions exist for which the function needs to be evaluated. Therefore the plot function will evaluate the boundary conditions.

Perhaps in SMath something similar could be implemented s.t. when a function is passed into the plot and it is specified as a piecewise function, it will evaluate any conditions specified within the range that aren't part of the auto-generated range.

I'm not certain if it's necessary to indicate that a function is intended to be piecewise continous within SMath or if SMath is smart enough to determine intent by the structure of the function itself. I do not think, generally, any function with conditionals can be considered piecewise, but I'm not sure if that's true.
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#12 Posted: 11/21/2018 1:37:40 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

Please tell me how it should look like.


Answer @ post # 8. Conditions are either true/false... Not maybe YES/maybe NO.

AdAbsurdum.PNG

#13 Posted: 11/21/2018 5:13:04 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Wrote



I'm not certain if it's necessary to indicate that a function is intended to be piecewise continous within SMath or if SMath is smart enough to determine intent by the structure of the function itself. I do not think, generally, any function with conditionals can be considered piecewise, but I'm not sure if that's true.



Hi. The only "true" piecewise function is Dirac's delta ... and it's a distribution, not a function. In maple you can convert from if's or some other to piecewise or step functions with 'convert', and in matlab (mupad, actually) with 'coerce'. Numeric or symbolic procedures for handling discontinuous plots have a lot of issues, and only works for "normal" functions, if not, think about how to implement procedures for plot x/sin(1/x) near zero.

But answering your question, my guess is not: assume that you implement an amazing routine for say that a number is rational or not (and then irrational: mathematica have something like that, or at least Wolfram think this). And then construct this function, and see this unusual, for say something, property

Clipboard08.gif

Best regards.
Alvaro
#14 Posted: 11/21/2018 1:04:22 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

I'm not certain if it's necessary to indicate that a function is intended to be piecewise continous within SMath or if SMath is smart enough to determine intent by the structure of the function itself. I do not think, generally, any function with conditionals can be considered piecewise, but I'm not sure if that's true.


Mon ami, your point is SO fundamental
Those things appeared ad-nauseum in Mathsoft Collaboratory.
Mathcad up to 11, was a bit more understanding, but wrong by principle
because confusing because not telling the truth. A piece-wise function
MUST be specified completely. On that, Smath is absolutely correct.

There are other things under the hood related to this discussion:
Integration of erf(x), and Gamma(x), the integrand must be vectorized.
Indirectly, it kind of depends upon of discontinuous approximation
of these two functions, the only two I have detected.

Most/most important about discontinuous is the major difference between
if/else and if/otherwise. Generally, they do the same but they aren't.
EXPLAIN: if/else is not scalar and it will not integrate a completely
specified if/else function. On the other hand, if/otherwise is scalar
thus will integrate. They both plot the same to add to the confusion.
Demonstrated => Integrate Discontinuous [Nuance].
Demonstrated => Where is the Dot Discrete.
It may even be more important if the path of integration is discontinuous.

Jean

Where is the dot discrete.sm (19 KiB) downloaded 41 time(s).
Integrate Discontinuous [Nuance].sm (24 KiB) downloaded 42 time(s).

#15 Posted: 11/22/2018 12:56:46 PM
Oscar Campo

Oscar Campo

124 likes in 298 posts.

Group: Moderator

Wrote

Hello!

I have a problem with simple equation. In case of my function, f(10) is equal to 5 but there is no "dot" of such value on the graph....



In a more compact form you can view no discontinuities

Captura de pantalla 2018-11-22 a la(s) 10.54.01 a. m..png
1 users liked this post
frapuano 11/22/2018 3:28:00 PM
#16 Posted: 11/22/2018 3:34:31 PM
frapuano

frapuano

13 likes in 115 posts.

Group: User

...It would be interesting to know why it works this way , just for sake of understanding; looks to me that the merging of several OR operations should be linked to this different (... and positive )behaviour.

Best regards

Franco
#17 Posted: 11/22/2018 3:54:18 PM
Davide Carpi

Davide Carpi

1415 likes in 2872 posts.

Group: Moderator

Wrote

...It would be interesting to know why it works this way , just for sake of understanding; looks to me that the merging of several OR operations should be linked to this different (... and positive )behaviour.

Best regards

Franco



They behave the same way; in the first post the plot was made with "Graph by points" enabled.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#18 Posted: 11/22/2018 5:29:35 PM
frapuano

frapuano

13 likes in 115 posts.

Group: User

Strange I had the idea that the graph in the first post was not with "Graph by points" enabled, I am starting to have more issues with my eyes than it was supposed to be.

Best regards

Franco
#19 Posted: 11/23/2018 1:32:02 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

The same plot in Mathcad will shows no apparent break @ 5.
Mathcad plots on ½ pica thus plots straight lines, thus not fine/pleasant look.
Smath plots on pixel thus the discontinuous were there is no ½ pixel.
A scalar function is a function that runs on a vanishing iterator 'x' .
Smath does not calculate ln(,), exp(,) ... it fetches from Windows.
Most if not all functions are approximations of 21 decimals.
i.e: Normalized Padé Rational Fractions.
Result may be only 18 Decimals. Thus, by convention results are
truncated to 15 decimals. Symbolic Engines is another story.
High accuracy Main-Frames may run Chebyshev of very high numerical
stability 25 decimals [typical Clenshaw ...]
Normalized Rational Fraction approximates on various best range wrt
to minimal arithmetic operations. Each function has its own specific range
generally very small. More numerical maths kind of scale the base range
to accommodate the 'x' of greater value than the base approximation,
naturally up to the max of the result < 10^307.
Before the event of rational approximations the first IBM used
continued fraction for the principal ln(x), exp(x), sqrt(x) ...

Can't help more about unknown math suite/use of the proposal.

scalarNOTscalar.PNG
#20 Posted: 11/23/2018 1:42:43 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

math suite ...


...in the if/otherwise '5' has no meaning.
Backspace to delete 5, type ".

  • New Posts New Posts
  • No New Posts No New Posts