Piecewise function representation of each piece

331 Views Asked by At

I've asked this question in MaplePrime, but wonder if any folks here can answer it as well.

I would like to find a way to represent each piece of a piecewise function in Maple.

For example, for a piecewise function:

f:=x->piecewise(1<=x<=2,c[1]*x+c[2],2<=x<=3,c[3]*x+c[4],3<=x<=4,c[5]*x+c[6]);

I want to have a way to retrieve each piece, e.g. c[3]*x+c[4], but f(x)[2] doesn't work.

Is it archievable?

2

There are 2 best solutions below

0
On BEST ANSWER

I believe that

op(2,f(x))

is what you are looking for. If your piecewises are always fully defined (i.e. no 'otherwise' branch), then

[seq(op(2*i, f(x)), i=1..nops(f(x))/2)]

would give you all the pieces.

2
On

I have not used Maple in a while, but I believe your function should be defined as follows:

f:=x-piecewise(1<=x<=2,c[1]*x+c[2],x<=3,c[3]*x+c[4],x<=4,c[5]*x+c[6]);

You have defined $f(2)$ two different ways:

  1. $f(2)= 2c_1+c_2$ and also as

  2. $f(2)=2c_3+c_4$

I believe that the piecewise function assumes that the sequence of values of $x$ where the function changes is an increasing sequence. So when you give the first interval as $1\le x\le2$ and the second as $x\le3$ it automatically assumes that the second interval begins where the last interval ended, so in this case it assume that the second interval is $2<x\le3$. Certainly one should take care that the same value of $x$ (in this case $x=2$) is not defined in two different intervals.