Items tagged with piecewise

 

 

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. 

 

 

Let:

f:=x->1/sqrt(2*Pi)*exp(-x^2/2);

I.e. f is a standard Gaussian PDF.

Then (in Maple 2016.1):

Int(convert(f(x)*f(y)*x*x*abs(x+y),piecewise,x),x=-infinity..infinity,y=-infinity..infinity):
evalf(%);

Returns:

1.692568751

However (again in Maple 2016.1):

int(convert(f(x)*f(y)*x*x*abs(x+y),piecewise,x),x=-infinity..infinity,y=-infinity..infinity):
evalf(%);

Returns:

-0.5641895835

This is clearly incorrect, as the integral of a positive function must be positive.

This also seems to be a problem in which ever version of Maple is used behind the scenes on this forum.

int(convert(1/sqrt(2*Pi)*exp(-x^2/2)*1/sqrt(2*Pi)*exp(-y^2/2)*x*x*abs(x+y),piecewise,x),x=-infinity..infinity,y=-infinity..infinity)

gives:

int(convert(1/sqrt(2*Pi)*exp(-x^2/2)*1/sqrt(2*Pi)*exp(-y^2/2)*x*x*abs(x+y),piecewise,x),x=-infinity..infinity,y=-infinity..infinity)

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.

 

Mr.M.Anand

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''(x)+y'(x)+y(x)=F(x)

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

N0:=6:
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.

 

Hello,

Questions

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 ?


Download example.mw

 

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)

0

(1)

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

3.141592654

(2)

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

Pi

(3)

``


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.

Thoughts?

 

Download Heaviside-error.mw

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?

Hi guys,

 

I would like to convert a piecewise defined function of two variables into an if structure
Example :

F := (x,y) -> piecewise(x < 0, piecewise(y < 0, 0, 1), piecewise(y < 0, 1, 0));

What I expect is something like (the indentation is just for fun)
if x < 0 then
   if y < 0 then 0 else 1 end if;
else 
   if y < 0 then 1 else 0 end if;
 end if


I tried the following :

convert(F(x,y), `if`)  # but it only converts the "outer x condition" and keeps the "inner y conditions" unchanged

And next this :

map(u -> convert(u, `if`), F(x,y)):   # fails to give m
# and
map(u -> convert(u(x,y), `if`), F(x,y)): 
# ...

without success.

Can anoybody help me please.
I am also interested in an explanation of the reasons why the previous command do not work.

Thanks all

I have 2 questions.

 

1) The help pages discuss the use of functions described by piecewise when using dsolve. The examples are clear enough but nothing is said about using the numeric option and piecewise. I get an error message for a very simple example: y' +R(t) y^2 = 0. Are I correct in assuming that dsllve numeric cannot deal with piecwise continuous functions?

2) I tried to solve a system of 2 second order constant coefficient linear ODEs using dsolve. After a very long wait (over an hour) I gave up. I tried again using "method=laplace" and got an instant answer. I did not bother to mention it here but it occurred again, this time with a fourth order and second order constant coefficient system. Very strange! I know that the laplace transform is a very useful tool; shouldn't Maple also know that?

Howdy,

I am trying to create a mathmatical model that shows a predator-prey relationship along with seasonal variations (hibernation). I made two piecewise functions where one is "on" during the winter and the other is "off" during the winter and the model worked well for one unit of time. 

My problem is that I would like the piecewise functions to apply over an arbitrary amount of time units periods without having to set the range within the function itself for 100 units of time. I was thinking that a for loop would work but i'm not sure how I would impliment that.

Thanks in advance!!

Edit: 

Here's a little bit more info on the problem.

I have three O.D.E's in an array..

ode := {r'(t),h'(t),c'(t)}

which are dependent on a list of parameters..

constants := {a,b,...,s,w,c0,h0,r0};

where s and w are my piecewise functions.

I am able to solve the three odes using dsolve for one period of s and w.

Again, I'm really not sure where to start to make my model periodic.

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