[Date Index]
[Thread Index]
[Author Index]
Re: Vector Piecewise in 5.1
*To*: mathgroup at smc.vnet.net
*Subject*: [mg53067] Re: Vector Piecewise in 5.1
*From*: Maxim <ab_def at prontomail.com>
*Date*: Wed, 22 Dec 2004 04:53:07 -0500 (EST)
*References*: <200412191114.GAA17987@smc.vnet.net> <cq6djo$2mq$1@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
Here we have two separate errors:
In[1]:=
Integrate[Piecewise[{{{a, b}, x > 0}}, {c, d}], x]
Out[1]=
Internal`ToPiecewise[{x <= 0, x > 0}, {c*x, d*x, {a*x, b*x}}, True]
Hard to say what went wrong here, the function Internal`ToPiecewise is
Protected like other system symbols, but it doesn't have any definition.
Now the definite integral:
In[2]:=
Integrate[Piecewise[{{{a, b}, x > 0}}, {c, d}], {x, -1, 1}]
Out[2]=
a + b + c + d
The correct answer is {a + c, b + d}. This is a trivial error: when
summing the integrals over [-1, 0] and [0, 1], instead of adding up {a, b}
and {c, d} Mathematica does something like Total[{{a, b}, {c, d}},
Infinity], destroying the correct expression structure.
A vector piecewise function cannot be plotted directly, because when Plot
analyzes the expression it is given, it doesn't see a list and assumes
that the expression is a scalar. You have to use some workaround, for
example
pw = Piecewise[{{{x, 2*x}, x > 0}}, {0, 0}];
Plot[{pw[[1]], pw[[2]]}, {x, -1, 1}]
Another issue is that long Piecewise expressions are formatted
incorrectly: in the output of Piecewise[{{Sum[a[k], {k, 100}], x > 0}}] I
can see the terms only up to a[73], after that point horizontal scrolling
in the front end gets stuck.
I wonder what the reason was to make Piecewise a HoldAll function: the
example with Sum shows that you can't tell how the arguments will be
evaluated anyway.
Maxim Rytin
m.r at inbox.ru
On Mon, 20 Dec 2004 11:38:32 +0000 (UTC), Murray Eisenberg
<murray at math.umass.edu> wrote:
> And it seems that pw cannot directly be plotted, not even by using, e.g.,
>
> Plot[cf, {x, -1, 1}];
>
> after your definition of cf.
>
>
> Mark Fisher wrote:
>> To my surprise (and delight) it turns out that Piecewise in 5.1 can
>> handle vectors (to some extent):
>>
>> pw1 = Piecewise[{{x, x > 0}}]
>> pw2 = Piecewise[{{x2, x > 0}}]
>>
>> pw = PiecewiseExpand[{pw1, pw2}]
>>
>> This can even be compiled successfully:
>>
>> cf = Compile[{x}, Evaluate[pw]]
>>
>> And differentiated:
>>
>> D[pw, x]
>>
>> But not, however, integrated:
>>
>> Integrate[pw, x]
>>
>> (Worse, Integrate[pw, {x, 0, 3}] returns a scalar.)
>> Is this a bug or just the absence of an undocumented feature?
>>
>> --Mark
>>
>>
>
Prev by Date:
**Re: Information about subscripted function**
Next by Date:
**Re: How input stacked characters with vertical bar**
Previous by thread:
**Re: Vector Piecewise in 5.1**
Next by thread:
**Re: Vector Piecewise in 5.1**
| |