Skip to main content
deleted 127 characters in body
Source Link
wolfies
  • 8.8k
  • 1
  • 25
  • 54

This might be better suited to mathematica.stackexchange.com than here.

To answer the question, givenGiven say:

expr = Piecewise[{ {x^2 + 2*x - 4, 0 <= x <= 2}, 
                   {0, True}}]

... you can convert your Piecewise expression back into a list form using:

 aa = Internal`FromPiecewise[expr, True]  // Transpose

which returns:

{{x >= 0 && x <= 2, -4 + 2 x + x^2}, {x > 2 || x < 0, 0}}

Then, you can find the part that corresponds to x == 0 using:

Select[aa, (#[[1]] /. x -> 0) &]

which yields the case of interest to you:

> {{x >= 0 && x <= 2, -4 + 2 x + x^2}}

{{x >= 0 && x <= 2, -4 + 2 x + x^2}}

This might be better suited to mathematica.stackexchange.com than here.

To answer the question, given say:

expr = Piecewise[{ {x^2 + 2*x - 4, 0 <= x <= 2}, 
                   {0, True}}]

... you can convert your Piecewise expression back into a list form using:

 aa = Internal`FromPiecewise[expr, True]  // Transpose

which returns:

{{x >= 0 && x <= 2, -4 + 2 x + x^2}, {x > 2 || x < 0, 0}}

Then, you can find the part that corresponds to x == 0 using:

Select[aa, (#[[1]] /. x -> 0) &]

which yields the case of interest to you:

> {{x >= 0 && x <= 2, -4 + 2 x + x^2}}

Given say:

expr = Piecewise[{ {x^2 + 2*x - 4, 0 <= x <= 2}, 
                   {0, True}}]

... you can convert your Piecewise expression back into a list form using:

 aa = Internal`FromPiecewise[expr, True]  // Transpose

{{x >= 0 && x <= 2, -4 + 2 x + x^2}, {x > 2 || x < 0, 0}}

Then, you can find the part that corresponds to x == 0 using:

Select[aa, (#[[1]] /. x -> 0) &]

{{x >= 0 && x <= 2, -4 + 2 x + x^2}}

Post Migrated Here from math.stackexchange.com (revisions)
Source Link
wolfies
  • 8.8k
  • 1
  • 25
  • 54

This might be better suited to mathematica.stackexchange.com than here.

To answer the question, given say:

expr = Piecewise[{ {x^2 + 2*x - 4, 0 <= x <= 2}, 
                   {0, True}}]

... you can convert your Piecewise expression back into a list form using:

 aa = Internal`FromPiecewise[expr, True]  // Transpose

which returns:

{{x >= 0 && x <= 2, -4 + 2 x + x^2}, {x > 2 || x < 0, 0}}

Then, you can find the part that corresponds to x == 0 using:

Select[aa, (#[[1]] /. x -> 0) &]

which yields the case of interest to you:

> {{x >= 0 && x <= 2, -4 + 2 x + x^2}}