Piecewise-command

mikkelstouby shared this idea 7 years ago
Under Consideration

Hi developers,


I already know how to nest if-statements to draw a piecewise-defined function but my students find this way hard.

I would therefore suggest a new command Piecewise[] where i.e. f(x)=Piecewise[x<1,x+2,x>=1,x] would be interpreted the same way as f(x)=If[x<1,x+2,If[x>=1,x]]. Such a command exists in Maple and I can see that my students have far less trouble using this.


Regards,

Mikkel

Comments (5)

photo
1

Hi developers,


I already know how to nest if-statements to draw a piecewise-defined function but my students find this way hard.

I would therefore suggest a new command Piecewise[] where i.e. f(x)=Piecewise[x<1,x+2,x>=1,x] would be interpreted the same way as f(x)=If[x<1,x+2,If[x>=1,x]]. Such a command exists in Maple and I can see that my students have far less trouble using this.


Regards,

Mikkel


f(x)=Piecewise[<relation>,<expression>,<relation>,<expression>,...] for multiple pieces, or perhaps more useful to learning


f(x)=Piecewise[<expression1>,<relation1>,<expression2>,<relation2>,...] to match the way these type of function are expressed mathematically. Looking at your algebra view.


Tony


BTW, g(x)=x+2,x>=1 work for individual equations


    g(x)=x+2,x<1

    h(x)=x,x>=1

    f(x)=g(x)+h(x)

This may be a reason it will not be done.

photo
1

hello

have tried If[x<1,x+2,x>=1,x] really?

saludos

photo
1

I did not know that, Mathmagic! That is indeed a nice feature. Thank you! My students will be thrilled.

I think this should be documented in the wiki.


Regards,

Mikkel

photo
1

Noel, the use that is documented is limited to If[condition, expression, expression]. That you can also use the syntax If[condition, expression, condition, expresion...] is not obvious.

photo
1

Yes, I tried to give the simplest example but I guess it became a little too simple. :)

© 2023 International GeoGebra Institute