[Date Index]
[Thread Index]
[Author Index]
Re: Solve and Piecewise Functions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg76439] Re: Solve and Piecewise Functions
*From*: Szabolcs <szhorvat at gmail.com>
*Date*: Tue, 22 May 2007 02:51:49 -0400 (EDT)
*Organization*: University of Bergen
*References*: <f2rqtl$9u1$1@smc.vnet.net>
Michael Madrid wrote:
> I was hoping something like this:
>
>
> Clear["*"]
> g=Piecewise[{{0,x<0},{2 x-x^2,0<=x<4},{16 x-x^2,x³4}}]
> h=x-2;
> Solve[g?h,x]
>
>
> would give me a meaningful answer. But all I get is this:
>
>
> Solve[\[Piecewise]{
> {0, x<0},
> {2 x-x2, 0£x<4},
> {16 x-x2, x³4}
> }?-2+x,x]
>
> Any thoughts on how to do this?
>
I don't think that Solve understands piecewise functions ...
You could use Solve separately for the three pieces, then pick those
solutions that satisfy the conditions.
In[1]:= pwSolve[HoldPattern[Piecewise][pw_List, ___] == rhs_, x_] :=
With[{sol = Solve[#1 == rhs, x]}, Pick[sol, #2 /. sol]] & @@@ pw
In[3]:= g =
Piecewise[{{0, x < 0}, {2 x - x^2, 0 <= x < 4}, {16 x - x^2,
x >= 4}}]
Out[3]= \[Piecewise] {
{0, x < 0},
{2 x - x^2, 0 <= x < 4},
{16 x - x^2, x >= 4}
}
In[4]:= h = x - 2
Out[4]= -2 + x
In[5]:= pwSolve[g == h, x]
Out[5]= {{}, {{x -> 2}}, {{x -> 1/2 (15 + Sqrt[233])}}}
Note that this simple pwSolve ignores the default value of Piecewise ...
Szabolcs
Prev by Date:
**Re: Re: change $UserDocumentsDirectory**
Next by Date:
**Re: Re: v. 6, third argument to rectangle**
Previous by thread:
**Re: Solve and Piecewise Functions**
Next by thread:
**Add On Packages**
| |