piecewise.mws

Piecewise defined functions and their graphs

> with(plots): This package is needed for the display command below.

Warning, the name changecoords has been redefined

> with(plottools): This package is needed for the disk and circle commands below.

> f:=x->piecewise(x<=0,0, x>0 and x<=1, x^2, x>1 and x<=2, 3-x, x>2,1+2*(x-2));
Define a function in a piecewise manner.

f := proc (x) options operator, arrow; piecewise(x ...

> f(x); This is how to see the formula for f. Maple has a strange way of listing the cases!

PIECEWISE([0, x <= 0],[x^2, -x < 0 and x-1 <= 0],[3...

> r:=0.03; Radius for open and closed circles in the plot. This needs to be chosen case by case, and if the x and y axes have different scales, the circles will become ellipses!

r := .3e-1

> p1:=plot(f,-2..3,discont=true,color=black,thickness=3): Note that you do not need the letter x here.

> p2:=disk([1,1],r,color=white,thickness=2): A white disk. Unfortunately, it doesn't color over the graph of f .

> p3:=circle([1,1],r,color=black,thickness=2): An open circle.

> p4:=disk([1,2],r,color=black): A closed circle.

> display({p1,p3,p4});

[Maple Plot]

Multiple plots

> plot([sin(1/x),cos(x)+1,2,2-(1/2)*x^2],x=0..Pi/2,linestyle=[1,2,3,4],color=black,legend=["A wiggly function","A trig function","A linear approximation","A quadratic approximation"]);

[Maple Plot]

> plot([sin(1/x),cos(x)+1,2,2-(1/2)*x^2],x=0..Pi/2,numpoints=500,linestyle=[1,2,3,4],color=black); With so many points, you can't distinguish the dash-dot and dashed lines from solid.

[Maple Plot]