Skip to main content
deleted 9 characters in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k

Here is one method, now more robust:

pwSplit[_[pairs : {{_, _} ..}]] := Piecewise[{#}, Indeterminate] & /@ pairs pwSplit[_[pairs : {{_, _} ..}, expr_]] := Append[pwSplit@{pairs}, pwSplit@{{{expr, Nor @@ pairs[[All, 2]]}}}] 

Testing:

pw = Piecewise[{{x^2, x < 0}, {x, 2 > x > 0}, {Log[x], x > 2}}]; Plot[Evaluate[pwSplit@pw], {x, -2, 4}, PlotStyle -> Thick, Axes -> False] 

Mathematica graphics

pw = Integrate[Piecewise[{{E^x, x^2 <= 1}}, Sin[x]], x]; Plot[Evaluate[pwSplit @ pw], {x, -2, 2}, PlotStyle -> Thick, PlotRange -> Full] 

Mathematica graphics


I like Heike's method so much I have to do my own version of it.

Module[{i = 1}, Plot[pw, {x, -2, 2}, PlotStyle -> Thick] /. Linex_Line -:> ({ColorData[1][i++], Line[##]x} &) ] 

Mathematica graphics

Here is one method, now more robust:

pwSplit[_[pairs : {{_, _} ..}]] := Piecewise[{#}, Indeterminate] & /@ pairs pwSplit[_[pairs : {{_, _} ..}, expr_]] := Append[pwSplit@{pairs}, pwSplit@{{{expr, Nor @@ pairs[[All, 2]]}}}] 

Testing:

pw = Piecewise[{{x^2, x < 0}, {x, 2 > x > 0}, {Log[x], x > 2}}]; Plot[Evaluate[pwSplit@pw], {x, -2, 4}, PlotStyle -> Thick, Axes -> False] 

Mathematica graphics

pw = Integrate[Piecewise[{{E^x, x^2 <= 1}}, Sin[x]], x]; Plot[Evaluate[pwSplit @ pw], {x, -2, 2}, PlotStyle -> Thick, PlotRange -> Full] 

Mathematica graphics


I like Heike's method so much I have to do my own version of it.

Module[{i = 1}, Plot[pw, {x, -2, 2}, PlotStyle -> Thick] /. Line -> ({ColorData[1][i++], Line[##]} &) ] 

Mathematica graphics

Here is one method, now more robust:

pwSplit[_[pairs : {{_, _} ..}]] := Piecewise[{#}, Indeterminate] & /@ pairs pwSplit[_[pairs : {{_, _} ..}, expr_]] := Append[pwSplit@{pairs}, pwSplit@{{{expr, Nor @@ pairs[[All, 2]]}}}] 

Testing:

pw = Piecewise[{{x^2, x < 0}, {x, 2 > x > 0}, {Log[x], x > 2}}]; Plot[Evaluate[pwSplit@pw], {x, -2, 4}, PlotStyle -> Thick, Axes -> False] 

Mathematica graphics

pw = Integrate[Piecewise[{{E^x, x^2 <= 1}}, Sin[x]], x]; Plot[Evaluate[pwSplit @ pw], {x, -2, 2}, PlotStyle -> Thick, PlotRange -> Full] 

Mathematica graphics


I like Heike's method so much I have to do my own version of it.

Module[{i = 1}, Plot[pw, {x, -2, 2}, PlotStyle -> Thick] /. x_Line :> {ColorData[1][i++], x} ] 

Mathematica graphics

added 277 characters in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k

Here is one method, now more robust:

pwSplit[_[pairs : {{_, _} ..}]] := Piecewise[{#}, Indeterminate] & /@ pairs pwSplit[_[pairs : {{_, _} ..}, expr_]] := Append[pwSplit@{pairs}, pwSplit@{{{expr, Nor @@ pairs[[All, 2]]}}}] 

Testing:

pw = Piecewise[{{x^2, x < 0}, {x, 2 > x > 0}, {Log[x], x > 2}}]; Plot[Evaluate[pwSplit@pw], {x, -2, 4}, PlotStyle -> Thick, Axes -> False] 

Mathematica graphics

pw = Integrate[Piecewise[{{E^x, x^2 <= 1}}, Sin[x]], x]; Plot[Evaluate[pwSplit @ pw], {x, -2, 2}, PlotStyle -> Thick, PlotRange -> Full] 

Mathematica graphics


I like Heike's method so much I have to do my own version of it.

Module[{i = 1}, Plot[pw, {x, -2, 2}, PlotStyle -> Thick] /. Line -> ({ColorData[1][i++], Line[##]} &) ] 

Mathematica graphics

Here is one method, now more robust:

pwSplit[_[pairs : {{_, _} ..}]] := Piecewise[{#}, Indeterminate] & /@ pairs pwSplit[_[pairs : {{_, _} ..}, expr_]] := Append[pwSplit@{pairs}, pwSplit@{{{expr, Nor @@ pairs[[All, 2]]}}}] 

Testing:

pw = Piecewise[{{x^2, x < 0}, {x, 2 > x > 0}, {Log[x], x > 2}}]; Plot[Evaluate[pwSplit@pw], {x, -2, 4}, PlotStyle -> Thick, Axes -> False] 

Mathematica graphics

pw = Integrate[Piecewise[{{E^x, x^2 <= 1}}, Sin[x]], x]; Plot[Evaluate[pwSplit @ pw], {x, -2, 2}, PlotStyle -> Thick, PlotRange -> Full] 

Mathematica graphics

Here is one method, now more robust:

pwSplit[_[pairs : {{_, _} ..}]] := Piecewise[{#}, Indeterminate] & /@ pairs pwSplit[_[pairs : {{_, _} ..}, expr_]] := Append[pwSplit@{pairs}, pwSplit@{{{expr, Nor @@ pairs[[All, 2]]}}}] 

Testing:

pw = Piecewise[{{x^2, x < 0}, {x, 2 > x > 0}, {Log[x], x > 2}}]; Plot[Evaluate[pwSplit@pw], {x, -2, 4}, PlotStyle -> Thick, Axes -> False] 

Mathematica graphics

pw = Integrate[Piecewise[{{E^x, x^2 <= 1}}, Sin[x]], x]; Plot[Evaluate[pwSplit @ pw], {x, -2, 2}, PlotStyle -> Thick, PlotRange -> Full] 

Mathematica graphics


I like Heike's method so much I have to do my own version of it.

Module[{i = 1}, Plot[pw, {x, -2, 2}, PlotStyle -> Thick] /. Line -> ({ColorData[1][i++], Line[##]} &) ] 

Mathematica graphics

added 69 characters in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k

Here is one method, now more robust:

pwSplit[_[pairs : {{_, _} ..}]] := Piecewise[{#}], Indeterminate] & /@ pairs pwSplit[_[pairs : {{_, _} ..}, expr_]] := Append[Piecewise[Append[pwSplit@{#}] & /@ pairs}, Piecewise[pwSplit@{{{expr, Nor @@ pairs[[All, 2]]}}]] }] 

Testing:

pw = Piecewise[{{x^2, x < 0}, {x, 2 > x > 0}, {Log[x], x > 2}}]; Plot[Evaluate[pwSplit @ pw]Plot[Evaluate[pwSplit@pw], {x, -2, 4}], PlotStyle -> Thick, Axes -> False] 

Mathematica graphicsMathematica graphics

pw = Integrate[Piecewise[{{E^x, x^2 <= 1}}, Sin[x]], x]; Plot[Evaluate[pwSplit @ pw], {x, -2, 2}, PlotStyle -> Thick, PlotRange -> Full] 

Mathematica graphics


There are still problems to work out, but this is a good start I think.Mathematica graphics

Here is one method, now more robust:

pwSplit[_[pairs : {{_, _} ..}]] := Piecewise[{#}] & /@ pairs pwSplit[_[pairs : {{_, _} ..}, expr_]] := Append[Piecewise[{#}] & /@ pairs, Piecewise[{{expr, Nor @@ pairs[[All, 2]]}}]]  pw = Piecewise[{{x^2, x < 0}, {x, 2 > x > 0}, {Log[x], x > 2}}]; Plot[Evaluate[pwSplit @ pw], {x, -2, 4}] 

Mathematica graphics

pw = Integrate[Piecewise[{{E^x, x^2 <= 1}}, Sin[x]], x]; Plot[Evaluate[pwSplit @ pw], {x, -2, 2}, PlotRange -> Full] 

Mathematica graphics


There are still problems to work out, but this is a good start I think.

Here is one method, now more robust:

pwSplit[_[pairs : {{_, _} ..}]] := Piecewise[{#}, Indeterminate] & /@ pairs pwSplit[_[pairs : {{_, _} ..}, expr_]] := Append[pwSplit@{pairs}, pwSplit@{{{expr, Nor @@ pairs[[All, 2]]}}}] 

Testing:

pw = Piecewise[{{x^2, x < 0}, {x, 2 > x > 0}, {Log[x], x > 2}}]; Plot[Evaluate[pwSplit@pw], {x, -2, 4}, PlotStyle -> Thick, Axes -> False] 

Mathematica graphics

pw = Integrate[Piecewise[{{E^x, x^2 <= 1}}, Sin[x]], x]; Plot[Evaluate[pwSplit @ pw], {x, -2, 2}, PlotStyle -> Thick, PlotRange -> Full] 

Mathematica graphics

added 362 characters in body
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k
Loading
Source Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k
Loading