MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: One thing in two ways, with different result.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90106] Re: One thing in two ways, with different result.
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sun, 29 Jun 2008 05:35:06 -0400 (EDT)

On 6/28/08 at 5:55 AM, damayi at gmail.com (damayi) wrote:

>Dear all, Today I encountered a confused question, and I hope you
>can help me. I defined a function g[x] in the following and Plot it.

>g[x_] := x^3 /; x <= 0
>g[x_] := x /; 0 < x <= 1
>g[x_] := Sin[x] /; x > 1

>Then I defined another function f[x] that is the same as g[x] in my
>opinion, and Plot it.

>f[x_] := Piecewise[{{x^3, x <= 0}, {x, 0 < x <= 1}, {Sin[x], x > 1}}=
]

>You will find that Plot[g[x],{x,-2,3}] is different with Plot[f[x],
>{x,-2,3] when x is 1.0

>Since g[x] and f[x] are identify, why are these plot different ? By
>the way, my Mathematica is 6.0.2.

My *guess* would be WRI has built-in to Plot the ability to
recognize Piecewise causing Plot to not connect two points on
opposite sides of a discontinuity. Assuming this is the case, it
seems reasonable to conclude a function not defined using
Piecewise has no way to trigger a similar behavior. So, Plot
will connect points on opposite sides of a discontinuity.

I labeled this as a guess since my quick check of the
documentation doesn't indicate Plot should behave in this manner.

What I find even more interesting is the difference between

Plot[g[x], {x, .9, 1.1}, Mesh -> All]

and

Plot[f[x], {x, .9, 1.1}, Mesh -> All]

The line connecting points on opposite sides of the
discontinuity still exists and the position of the sampled
points seems as should be expected given the adaptive sampling
routine used by Plot.

But the Plot of f[x] shows a sampled point half way between the
groupings of points on either side of the discontinuity. How is
this to be interpreted this given the definition of f?


  • Prev by Date: Re: Replacing elements in a list
  • Next by Date: Re: A set of several questions
  • Previous by thread: Re: One thing in two ways, with different result.
  • Next by thread: Re: One thing in two ways, with different result.