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: [mg90116] Re: One thing in two ways, with different result.
  • From: "David Park" <djmpark at comcast.net>
  • Date: Sun, 29 Jun 2008 05:36:56 -0400 (EDT)
  • References: <g451vv$pqg$1@smc.vnet.net>

A nice example!

This is the advantage of using Piecewise over multiple conditional 
definitions. With Piecewise Mathematica can find the breakpoints provided 
simple intervals are given. But not with multiple conditional definitions. 
It then excludes the breakpoints. But you could specify the breakpoints by 
using the Exclusions option.

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

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

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

Plot[g[x], {x, -2, 3}]

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

Piecewise seems to work even if we try to disguise where the breakpoints 
are. Probably because Mathematica  u uses Reduce on the conditions before 
plotting.

h[x_] := Piecewise[{{x^3, x <= 0}, {x,
    0 < x^2 <= 4 \[And] x > 0}, {Sin[x], x^2 > 4 \[And] x > 0}}]
Plot[h[x], {x, -2, 5}]

-- 
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/


"damayi" <damayi at gmail.com> wrote in message 
news:g451vv$pqg$1 at smc.vnet.net...
> 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: A set of several questions
  • Next by Date: Re: How to show PolarPlot with circles coordinate
  • Previous by thread: Re: One thing in two ways, with different result.
  • Next by thread: Re: One thing in two ways, with different result.