MathGroup Archive 2008

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

Search the Archive

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


Piecewise automatically excluded the discontinuity. Without Piecewise you need to explicitly exclude it from the Plot using the option Exclusions.

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

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

Plot[f[x], {x, -1, 2}]

Plot[g[x], {x, -1, 2}, Exclusions -> 1]


Bob Hanlon

---- damayi <damayi at gmail.com> 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.
> 
> Best Regards
> mayi
> 2008-6-27
> 



  • Prev by Date: Re: Export PDF plot or Save Selection As -- big troubles with
  • Next by Date: Re: One thing in two ways, with different result.
  • Previous by thread: Re: One thing in two ways, with different result.
  • Next by thread: Re: One thing in two ways, with different result.