Items tagged with piecewise piecewise Tagged Items Feed


I have problem with 3Dplotting of this piecewise...can anyone help me please?!

since i know the output will be a value between 0 and 1 can i plot it for different values of Mu in this range to eliminate a dimension?

Mu(x1, x2, x3) = piecewise(`or`(`or`(x1 > 55, x2 > 10), y >= 2), 1, x1 < 35 and x2 <= 10 and x3 < 1, (1/10)*x2, `and`(`and`(x1 < 35 and x2 <= 10, x3 >= 1), x3 <= 2), max((1/10)*x2, x3-1), `and`(`and`(`and`(x1 >= 35, x1 <= 55), x2 <= 10), x3 <= 1), 1-((55-x1)*(1/20))((10-x2)*(1/10)), `and`(`and`(`and`(`and`(x1 >= 35, x1 <= 55), x2 <= 10), x3 >= 1), x3 <= 2), max(x3-1, 1-((55-x1)*(1/20))((10-x2)*(1/10))))

Thank you very much in advance...

how can you graph when piecewise function is not continuous?



BB := piecewise (-1.57 < c and c < -1.56, h, -0.06< c and  c < -0.05, aa, -0.5< c and c < 0.04, bb);




I have this code generating a piecewise function:

> with(CurveFitting);

> points := [[0, 1], [1, 2.5], [3, 2.3], [4.2, 5], [5, 3.5], [5.8, 4.2], [7, 7], [8, 10]];

> splcurve := Spline(points, v);

In this particular case I have seven distinct polynomials. Someone knows how could I get one specific polynomial, for example, the one exactly before v < 4.2? 

In other terms:

I'd like to define a new function, say 'f', that is exactly the polynomial just before v < 4.2 (e.g, something like f:=(splcurve, v < 4.2)). Do exists this possibility? (I have been looking for it elsewhere but without success!!)

Thanks in advance! Best regards!


When plotting a continous function that looks something like a square wave, for example like this:

a:=0: b:=2*Pi: p:=b-a:
fp:=f(x-floor( (x-a)/p)*p);

Is there some way to show dashed vertical lines at the points of discontinuity?

If we have a piecewise continous 2*Pi-periodic function

h(t)=e^(2*t) when 0 < t < 2*Pi

How can we plot it? It should look something like this:


Periodic plot


I.e. I want to be able to just set an interval and then it automatically plots the function with the specified periodicity.

I've got the following piecewise function :

(x^2+y^2)^(alpha).arcsin(y/x) if (x,y) are in [-pi/2,pi/2]

0, (x,y)=(0,0)

1. How do I plot this function taking the alpha variable and the piecewise construct into account?

2. How can I check for points of discontinuity, indifferentiability from the plot/function itself?



I've got a piece-wise function(for which I've made the procedure) f defined over x<=-1, -1<x<1 and x>=1 which I am trying to plot over the range of (-2,2). I've tried using plot(f,-2..2) but it doesn't show any curve. Should I add a few more parameters to plot()?

Hi there,

I am trying to maximize a function given a set of values to a parameter in the function. The function is an differential equation belonging to a system of two differential equations.

I have a for loop to state different values to the parameter.

Maple yields the error:

Error, (in Optimization:-NLPSolve) cannot evaluate the solution further right of 0.17757507e-4, probably a singularity

When trying to maximize the function.

Supposed that I was doing something wrong in the loop, if I reproduce the contents of the loop outside, and set a value for the parameter. If I plot the solution of the ordinary differential equation, I can see where the maximum lies.

Having plot it, the Optimizamtion:-Maximize works as expected.

However, omitting the plot has a weird effect: I only get the same result depending on the bounds I set for the Maximization:

de1 := diff(A(t), t) = r*m*(1-g)*A(t)-piecewise(t < 8, r*A(t), t >= 8, (r+k)*A(t));
de2 := diff(G(t), t) = r*m*g*A(t)-l*G(t);

ics := A(0) = 25.0, G(0) = 0.;
num := dsolve({de1, de2, ics}, {A(t), G(t)}, type = numeric, output = listprocedure, parameters = [g]);

num(parameters = [g = .15]);
val := eval(G(t), num);

# odeplot(val, [t, G(t)], t = 0 .. 100);

Error, (in Optimization:-NLPSolve) cannot evaluate the solution further right of 0.17757507e-4, probably a singularity

val2 := Maximize(val);

Error, (in Optimization:-NLPSolve) cannot evaluate the solution further right of 0.17757507e-4, probably a singularity

val3 := Maximize(val(t), t = 0 .. 60);

  [10267.824035766165, [t = 8.25727747134303]]

val4 := Maximize(val(t), t = 0 .. 100);

[6.863211343195069e-9, [t = 59.84184367042171]]


The right answer is [10267.824035766165, [t = 8.25727747134303]]: Why do I get two different answers even if in that range there is only one relative maximum?

I ignore whether the way I am specifying the arguments for the Maximize function is correct. val is a procedure.


What am I missing?

Attached is the worksheet:




A function f is defined on R by


f(x):= (1+a|x|)^1/x      , x<0

         B                      ,  x=0

         ln(1+(a^2)|x|)/x , x>0


where α and β are constants. Investigate whether it is possible to choose α and β so
as to ensure that f is real-valued and continuous at x = 0. Compute any such values
for α and β correct to 10 significant figures. Make use of the piecewise command in
plotting a graph of any resulting continuous function(s) f over the range −20 ≤ x ≤ 20.


I used the help in Maple and manage to get 

f = piecewise(x < 0, (1+alpha*abs(x))^(1/x), x = 0, beta, x > 0, ln(1+alpha^2*abs(x))/x)


Not sure about how to compute a and B...

What does it mean by  f is real-valued and continuous at x = 0?


Maple does not cancel out a variable.

Why is that?

Is there a way to solve this? 

(I pasted my code on the bottom of this message)


Thanks for your help/advice,


# simplify() does not work.....?
M(x):=simplify(%) assuming EI>0;
# Wiht EI cancelled out by hand it schould look like:


Hi all

kx,ky is the wavenumber, how can I get the 4 cases of piecewise function according to kx=0,kx≠0 and ky=0,ky≠0. Thanks

J := `assuming`([4*(int(int(JJ*exp(-I*(kx*x+ky*y))*sin(2*l*pi*x/a)*sin(2*k*pi*y/b), x = 0 .. a, AllSolutions), y = 0 .. b, AllSolutions))/(a*b)], [k::posint, l::posint, a > 0, b > 0, JJ > 0])



I'm trying to make a piecewise function that will have period 12. That is, it repeats every 12 units across the x-axis.


I managed to do one cycle successfully with

plot(piecewise(0<=t and t<2, 4,2<=t and t<12,0), t=0..13);

But I'm not sure how to do it periodically. I thought about using modular arithmetic in the conditions and setting up something like

H(t)=piecewise(0<=modp1(f(t),12) and modp1(f(t),12)<2, 4,2<=modp1(f(t),12) and modp1(f(t),12)<12,0);

but this clearly doesn't work.


Some direction or advice would be appreciated. Thanks!


Hi all

I have a mathematical problem and I asked it in various sites but the answers till yet are not correct.

Assume that we have:

b[n,m]:=unapply(piecewise(t>=(n-1)*tj/N and t<n*tj/N, T[m](N*t-(n-1)*tj), 0), t):

where n,N,tj are known constants. furthermore assume that we want to comute the following integral:

for following approximations:

I have written the following code but it seems to be incorrect:


the original program is :


I will be so grateful if any one can help me to solve it by maple

Mahmood   Dadkhah

Ph.D Candidate

Applied Mathematics Department

hi all.

I have wrore the following program for optimization with bernstein and block pulse hybrid functions.

the program have some errors which i can't understand.



macro(LA= LinearAlgebra):

HybrFunc:=proc(N, M,  tj)               # N=Number of subintervals,  M=Number of functions in subintervals
local B, n, m;

global b;

for n from 1 to N do
for m from 0 to M-1 do

B := (i,m,t) -> C(m,i)*(1-t)^(m-i)*t^i:

b[n,m]:=unapply(piecewise(t>=(n-1)*tj/N and t<n*tj/N, B(m,2,N*t-(n-1)*tj), 0), t):

Array(1..N, 0..M-1, (n,m)->b[n,m](t)):

end proc:

HybrFunc(3, 3, 1);

                                       # End Of Definition
g2(t):=t;            #*exp(t-1):                      # Any other function can be replaced here

g1(t):=add(add(c[n,m]*b[n,m](t), m=0..2), n=1..3);
Optimization[Minimize](sqrt(int((g2(t)-g1(t))^2, t=0.. 1)));
plot([g2(t),g1(t)], t=0..1, 0..5, color=[blue,red],thickness=[1,3],discont, scaling=constrained);

Array(1 .. 3, 0 .. 2, {(1, 0) = piecewise(0 <= t and t < 1/3, (1-3*t)^2, 0), (1, 1) = piecewise(0 <= t and t < 1/3, (6*(1-3*t))*t, 0), (1, 2) = piecewise(0 <= t and t < 1/3, 9*t^2, 0), (2, 0) = piecewise(1/3 <= t and t < 2/3, (2-3*t)^2, 0), (2, 1) = piecewise(1/3 <= t and t < 2/3, (2*(2-3*t))*(3*t-1), 0), (2, 2) = piecewise(1/3 <= t and t < 2/3, (3*t-1)^2, 0), (3, 0) = piecewise(2/3 <= t and t < 1, (3-3*t)^2, 0), (3, 1) = piecewise(2/3 <= t and t < 1, (2*(3-3*t))*(3*t-2), 0), (3, 2) = piecewise(2/3 <= t and t < 1, (3*t-2)^2, 0)}, datatype = anything, storage = rectangular, order = Fortran_order)

g2(t) := t

"g1(t):=c[1,0] ({[[(1-3 t)^2,0<=t and t<1/3],[0,otherwise]])+c[1,1] ({[[6 (1-3 t) t,0<=t and t<1/3],[0,otherwise]])+c[1,2] ({[[9 t^2,0<=t and t<1/3],[0,otherwise]])+c[2,0] ({[[(2-3 t)^2,1/3<=t and t<2/3],[0,otherwise]])+c[2,1] ({[[2 (2-3 t) (3 t-1),1/3<=t and t<2/3],[0,otherwise]])+c[2,2] ({[[(3 t-1)^2,1/3<=t and t<2/3],[0,otherwise]])+c[3,0] ({[[(3-3 t)^2,2/3<=t and t<1],[0,otherwise]])+c[3,1] ({[[2 (3-3 t) (3 t-2),2/3<=t and t<1],[0,otherwise]])+c[3,2] ({[[(3 t-2)^2,2/3<=t and t<1],[0,otherwise]])"

Error, (in Optimization:-NLPSolve) complex value encountered

Error, invalid left hand side in assignment


Download Bernestien1.mws

 I'll be so grateful if any one can help me.

Mahmood   Dadkhah

Ph.D Candidate

Applied Mathematics Department

Is it possible to solve piecewise differential equations directly instead of separating the pieces and solving them separately.

like for example if i have a two dimensional function f(t,x) whose dynamics is as follows:

dynamics:= piecewise((t,x) in D1, pde1, pde2); where D1 is some region in (t,x)-plane

now is it possible to solve this system with one pde call numerically?

pde(dynamics, boundary conditions, numeric); doesnot work

1 2 3 4 5 6 7 Page 1 of 7