Questions tagged [piecewise]

Questions about the Piecewise function, which is represented by different expressions for different ranges of values of its independent variable.

492 questions
10
votes
3 answers

How to efficiently get breakpoints of piecewise functions

Setting. Imagine that we have several arbitrary linear functions in 2D that can be changed manually (say, slopes are parameters). Their Min (or Max) gives a sort of piecewise continuous function. Example. Let us take three functions. try = {3 (1 -…
garej
  • 4,865
  • 2
  • 19
  • 42
8
votes
2 answers

Alternatives to piecewise

As has been mentioned before, Piecewise causes the Mathematica Kernel to fail to during a NDSolve calculation. How can I write the function below without using Piecewise? s[t_] := Piecewise[{{1, t < 300.}, {0, 300. <= t < 1500.}, {1, t <=…
tarhawk
  • 769
  • 5
  • 15
6
votes
1 answer

Troubles using Which or Piecewise to define a function

I have a very simple task, but for some reason I fail to accomplish it. I want to use Which to define a function. I think the code is self-explanatory: In: f[x_, y_] := Which[x == en, 1, y == en, 2] In: f[en, a] Out: 1 OK, so far so good. But if…
Luka
  • 133
  • 5
5
votes
1 answer

How to sort the ranges of a Piecewise expression?

I have the following PieceWise expression qq= Piecewise[{ {x/8, x <= -6}, {x/2, x >= 22 - 8*Sqrt[6]}, {(1/384)*(52 + 72*x + 3*x^2), -2 <= x <= 18 - 8*Sqrt[6]}, {(-14696 + 6144*Sqrt[6] + 468*x + 66*x^2 - x^3)/1536, 18 - 8*Sqrt[6]…
Jacob Akkerboom
  • 12,215
  • 45
  • 79
5
votes
4 answers

How to select a certain portion of a piecewise function?

For example, if I have Piecewise[{{x^2, x < 0}, {x, x > 0}}], how do I select only the function that is for x < 0? I want to set a new function equal to the x^2 only, not the entire piecewise function.
mikal94305
  • 153
  • 4
5
votes
1 answer

How can I combine two Piecewise functions?

I want to be able to combine two piecewise functions. For example, suppose Piecewise1 = f=3 for 1 <=x <=2 and Piecewise2 = f=5 for 1.5<=x<=3, I want to insert Piecewise2 into Piecewise1 such that I get: f=3 for 1
Giorgos
  • 51
  • 2
4
votes
2 answers

Create List of Functions using Piecewise

It sometimes is useful to combine such expressions as z1[t_] = Piecewise[{{Sin[t], Sin[t] > Cos[t]}}] z2[t_] = Piecewise[{{Cos[t], Sin[t] > Cos[t]}}] into something like {z1[t_], z2[t_]} = Piecewise[{{{Sin[t], Cos[t]}, Sin[t] >…
bbgodfrey
  • 61,439
  • 17
  • 89
  • 156
4
votes
4 answers

How to build a funcion that returns a piecewise function

I dont know how to go ahead with this The problem statement is "Make a piecewise linear function maker that accepts lists of points as input and has a piecewise linear function as the output". Lets say for example I have a data sect…
user11948
  • 171
  • 6
4
votes
1 answer

Put a standalone wall barrier inside a 2D square well potential

Here is the code for the 2D square well potential: v[x_, y_] := Piecewise[{{1, 58 < Abs[x]}, {1, 58 < Abs[y]}}]; Plot3D[v[x, y], {x, -70, 70}, {y, -70, 70}] Is Piecewise the right function to use? How do I put a standalone wall barrier inside this…
Michael B. Heaney
  • 1,637
  • 12
  • 18
4
votes
1 answer

What does True mean in this case?

I use the following code to find the expansion for small $x$: Assuming[x \[Element] Reals, FullSimplify@ Series[-Sqrt[-x] I^(n + 1/2) HankelH1[n, -x], {x, 0, 1}]] I find the solutions: Analogously: Assuming[x \[Element] Reals, FullSimplify@ …
mattiav27
  • 6,677
  • 3
  • 28
  • 64
3
votes
0 answers

How to get a list of discontinuous points from a piecewise function

I want to find a list of discontinuous points from a piecewise function. Suppose I have a function f[x_] = Piecewise[ { {x, -1 <= x < -0.1} ,{-2 x^2, -0.1 <= x < 1} } ] I want to get list like {-1,-0.1,1}.
Shabbir
  • 51
  • 1
3
votes
0 answers

Data paste in piecewise table

How can I paste data copied from several lines into a piecewise table, without pasting it in a single cell?
3
votes
1 answer

Piecewise function inside If statement or another Piecewise function breaks outputs

I have a calculation that outputs a piecewise function that has as its cases a list of expressions. An example (3 cases with each a list of 4 expressions) is below: pw[x_,y_]:=Piecewise[{{{a1,b1,c1,d1},x>5y},{{a2,b2,c2,d2},x<3y}},{a3,b3,c3,d3}] I…
John Smith
  • 153
  • 4
3
votes
3 answers

How to get edge values of the piecewise function if it has discontinuties

Qplot = Piecewise[{{Ray, h <= c/3}, {Ray-P, c/3 <= h <=c}, {Ray-P-q*(h-c) + X1, c <= h <= c+b}, {Ray-P-q*b + X1 + X2, c+b <= h <= c+b+a}}] As can be seen on the plot, this function has discontinuities on certain points (like c/3, c, etc). I…
3
votes
1 answer

Piecewise function extraction

I have a piecewise function and I'm trying to extract the different functions for different values of the parameter. I use: First/@(InitialEnvelope[\[Beta]]//PiecewiseExpand)[[1]] This gives be back the different functions except the last piece…
Rby
  • 159
  • 11
1
2 3