Items tagged with piecewise


Dear community, 

I'm new to maple and was wondering if you could help me out.

I have this curve where I want to make a line that goes from x=0.5 up to its value on the curve in this case 1.60 and then all the way to the y-axis so there is an area under the curve which I can color if that's even possible?

I have the following in maple:

k := 2.5;
Ca0 := 1;
v := 20;
Ca := Ca0*(1-x);
                             1 - x
Fa0 := Ca0*v;
Cb := Ca0*x;
ra := k*Ca*Cb;
                         2.5 (1 - x) x
plot(1/ra, x = 0 .. 1);

thank you for your help

Best Regards


I have a piecewise that exists on a large intervals, say [-5..15], however, I know need the function to represent [1..9].

There are two approaches I know of: using convert(f,pwlist) or using op(n,f), see attachments.    and  PiecewiseTruncate.pdf

However, these two methods are not elegant enough, I have to reassemble the pieces in the new function.

How to make the solution neat?


I want to plot a simple power function in diferent pieces by using diferent range and  for different values of parameter a[i] at i=0,1,2 define in the attached sheet.

I wonder if there is 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?



I tryed this, because i thought i might be abel to shade this new piecewise function later on, but i dont know how to tell maple that there is 2 y-axes values in the interval from (2;3):

so it failed. 

pleace help regards Niklas.



 I need help regarding this figure. i want to write both equations in maple 18. Second equation is related to first equation.So, please help me to write this code. I will be grateful. 



The piecewise plot below displays a sphere truncated by the plane z = 2 - y.

f := proc (x, y, z) options operator, arrow; piecewise(z <= 2-y, x^2+y^2+z^2-16, z-2+y) end proc; implicitplot3d(f, -4 .. 4, -4 .. 4, -4 .. 4, style = surface, numpoints = 50000);

The 3 transforms below when executed in display(T(sphere([0, 0, 0], 4, numpoints = 50000)), scaling = constrained) display the truncated sphere differently:

1) the truncating plane only partly conforms to the boundary of the truncated sphere

2) the truncated sphere is correct provided that the else condition coordinate is in the truncating plane and truncated sphere

3) the truncated sphere is correct but hollow


1) T := transform(proc (x, y, z) options operator, arrow; `if`(z <= 2-y, [x, y, z], [x, y, 2-y]) end proc)

2) T := transform(proc (x, y, z) options operator, arrow; `if`(z <= 2-y, [x, y, z], [0, 0, 2]) end proc)

3) T := transform(proc (x, y, z) options operator, arrow; `if`(z <= 2-y, [x, y, z], [`&+-`(sqrt(16-y^2-z^2)), y, 2-y]) end proc)

Please explain the different behavior of the three transforms.           

Good morning Maple Expert,


I would like to explain the concept of piecewise curves in 2D & 3D to my students with plots.In this regard I request the associated expetrs in Maple to provide the appropriate Maple commands to get piecewise curves in 3D space.


With warm regards.



Associate Professor in Mathematics.

Hyderabad Institute of Technology and Management

I try to solve numerically a boundary VP for ODE with different order of discontinuity of right part.

Say, the following BVP is given:


y(0)=1, y(2)=1

Let's use piecewise right part

F  := piecewise(x<=1, -x, x>1, 2*x+(x-1)^2)

plot(piecewise(x<=1, -x, x>1, 2*x+(x-1)^2), x=0..2,thickness=5)

The function

piecewise(x<=1, 1-x, x>1, (x-1)^2)

plot(piecewise(x<=1, 1-x, x>1, (x-1)^2), x=0..2, color=blue,thickness=5)

as obviuos, satisfies the BVP exclung the point x=1, where its 1st and 2nd derivatives are discontinuos.

Numerical solution

As:=dsolve([diff(y(x), x$2)+diff(y(x), x)+y(x)=F,  y(0)=1, y(2)=1], y(x), type=numeric, output = Array([seq(2.0*k/N0, k=0..N0)]), 'maxmesh'=500, 'abserr'=1e-3):

provides the solution essentially different to exact one described above:

But if to use the right part

F := piecewise(x<=1, x^2+x+2, x>1, -x^2+x)

plot(piecewise(x<=1, x^2+x+2, x>1, -x^2+x), x=0..2, color=blue,thickness=5)

for which the function

piecewise(x<=1, 1-x+x^2, x>1, -1+3*x-x^2)

plot(piecewise(x<=1, 1-x+x^2, x>1, -1+3*x-x^2), x=0..2, thickness=5)

satisfies the BVP excluding x=1, where this function has discontinuity of 2nd derivative only, the corresponding numerical solution is very similar to this exact solution:

This reason of the difference between these two cases is clear. In the first case both 1st and 2nd derivatives are discontiuos, while in the second one -- 1st derivative is contiuos.

I wonder, if there are numerical methods, implemeted in Maple, for numerical solution of the first type BVP with non-smooth right part?

I am having trouble with understanding how to use piecewise to define a function f such that

f(x) = 1 whenever the VALUE of x is an integer (thus f((2^(0.5) - 1.0)*(2^(0.5) + 1.0)) = 1).

f(x) = 0 otherwise.




1)  Can we compute the error  ( x(t-2*Pi) - x(t) )  without plotting  abs(  x( t-2*Pi ) - x(t) ) ?

     i.e. using norm 1, 2 or infinity  ?


2)  what is op( [ a, b, c] , F ),  where F is a piecewise function ?



The page ?type,piecewise shows the example

type(piecewise[](x < 1, a, b), 'piecewise');

and lines 4-8 of showstat(`print/piecewise`) deal with the case of an indexed piecewise. Yet I can find no other reference to indexed piecewise. What is it used for? When I put an index on a piecewise, nothing special seems to happen, either computationally or display-wise:

piecewise[abs](x > 0, x, -x);
piecewise[Carl](x > 0, x, -x);

The code in `print/piecewise` suggests that it serves some purpose.

I'm running into a very simple problem with the way that Maple integrates Heaviside functions. Naively, it should act like a step function, but it is not integrating properly. See the attached document.

int(int(Heaviside(-x^2-y^2+1), x = -1 .. 1), y = -1 .. 1)



evalf(Int(Heaviside(-x^2-y^2+1), [x = -1 .. 1, y = -1 .. 1]))



int(piecewise(-x^2-y^2+1 > 0, 1, 0), [x = -1 .. 1, y = -1 .. 1])




Note that the symbolic integration of the Heaviside function (defined to be 1 inside the unit circle and 0 outside) gives zero, whereas it should clearly give the area of the unit circle, which the numerical integration does. I even checked that the (suposedly equivalent) piecewise definition symbolically evaluates to the area, and it, too, gets the right answer.

Anyone have any clue as to why the symbolic integration of this Heaviside function is so wrong? My understanding is that if we do the integral as two nested 1D integrals, the returned function (as a function of y) is zero everywhere except at y=0, but that result cannot be right either.




Having a function where the value is for example only defined when abs(x) <= 1, then how can I specify that the value is otherwise undefined, the replacing "How_to_specify_undefined_value" below?

1 2 3 4 5 6 7 Last Page 1 of 9