Questions tagged [piecewise]

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

Filter by
Sorted by
Tagged with
1
vote
1answer
95 views

Priority of nested function in Mathematica

I am facing a small problem with the nested function in Mathematica. Please take a look at the attached Code below. ...
5
votes
1answer
141 views

UnitStep vs HeavisideTheta; KroneckerDelta vs DiscreteDelta

What are the differences between these pairs of functions? In many cases, they seem to act the same. For example, both DiscreteDelta and ...
5
votes
1answer
131 views

Does Mathematica have this function implemented?

Is there a function in Mathematica that can express a piecewise function in terms of the Heaviside theta function? Say, for example, the solution to this ODE.
0
votes
2answers
269 views

NDSolve with Piecewise function

I have the following code on Mathematica ...
2
votes
2answers
152 views

Defining a piecewise function with underlying lattice

I'm fairly new to Mathematica, and programming in general, but I'm trying to define an $n$-dimensional piecewise function, $F({\bf x})$. Properties of the function are set by an underlying lattice, ...
0
votes
1answer
144 views

FindRoot when variable is inside a piecewise function

I want to find the root of a function that has a piecewise part. This means that the value Mathematica will search will determine in which piece of the function we will be. I don't my example is the ...
2
votes
1answer
120 views

Unfamiliar output of FullSimplify [duplicate]

I got the following output of FullSimplify, when expecting to get "0". I found no explanation of this output here. Could you please explain, what it means? That my expression equals zero when the ...
1
vote
0answers
38 views

Unexpected behavior when copying a Piecewise expression

When I type a Piecewise function (e.g. Piecewise[{{a,0<a<1},{2a,1<a<2}}]) in mathematica notebook using ...
10
votes
7answers
2k views

How to plot a list to look like step function?

Suppose I have the following simple list. l = {0,2,5,9,14}; I want to to make a plot that looks like the figure below. I.e. I want to have a horizontal line ...
1
vote
2answers
217 views

Restricting a plot to be over integers

I am trying to plot the following function: ...
2
votes
2answers
218 views

ContourPlot combined with Piecewise bug

I'm plotting a two dimensional von Mises and Tresca yield surface and got: ...
1
vote
0answers
51 views

Strange behavior of NIntegrate

I have some function f[x,y,a], where a is some parameter, defined as piecewise f[x,y,a] = Piecewise[{{g[x,y,a], a<m[x]}, {0, True}}] Here $m$ is some function....
3
votes
1answer
642 views

What does True mean in this case? [duplicate]

I use the following code to find the expansion for small $x$: ...
0
votes
1answer
263 views

set colours for different parts of a piecewise function's graph [duplicate]

I would like to create a graph of the piecewise function $f(x) = \begin{cases} x + 2, & x < -1 \\ x^2, & -1 \leq x \leq 2 \\ 3, & x > 2\end{cases}$ where the changes in the ...
2
votes
0answers
84 views

I get gaps when use Plot3D combined with Piecewise [closed]

I am trying to plot a function that is Piecewise in both dimensions. I write this ...
4
votes
1answer
101 views

Simplify integral with piecewise expression

How can I simplify this integral? Integrate[Piecewise[{{c[x], 0 <= x <= 1/2}, {0, True}}], {x, 0, 1}] I think it should be the same as ...
1
vote
2answers
161 views

Plotting orbit of a discontinuous map

I'm trying to plot the orbit of a two dymensional discontinuous map. Could you help me please? I tried using Piecewise, but I didn't get the result I wanted. The ...
2
votes
1answer
304 views

Force derivative of piecewise function at boundary points to be one-sided derivative

I've defined a smooth step function given as f[x_] = Piecewise[{ {y0, x<x0-dx/2}, {y0+1/2(y1-y0)(1-Cos[Pi*x/dx]), x<x0+dx/2}, {y0, True} }]; ...
6
votes
3answers
427 views

Integrating a piecewise function with symbolic pieces

Suppose I want to compute the antiderivative of this simple function: $$f(t)=\begin{cases} 1 & \text{if $0\le t\le t_1$,} \\ -1 & \text{if $t_1\le t\le t_2$}, \\ 0 & \text{otherwise,} \end{...
2
votes
1answer
63 views

ColorFunction makes choppy line in Plot

I'm trying to apply a ColorFunction[] to a piecewise plot. For some reason, applying the ColorFunction[] to a plot results in ...
3
votes
3answers
91 views

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}}] ...
4
votes
1answer
90 views

Chop in Piecewise function

I'm trying to implement a complex square root with branch cut on the negative real axis; the (real part of the) second argument determines which branch to take. ...
3
votes
0answers
108 views

Simplifying Redundant Piecewise Cases

I would like to perform a summation from $1$ to $M$ of a simple piecewise function. For example, ...
1
vote
1answer
105 views

Cross-sections of a revolutionplot3D of a piece-wise function

I trying to get multiple cross-sections of a revolution plot I made from a piece-wise function. The end goal would be to calculate integrals underneath those cross-sections. my code looks like this: ...
2
votes
0answers
80 views

Piecewise function Syntax error only in debug mode

If I enter the following through mathematica (11.0) through UI $$\begin{cases} 1 &x \geq 0 \\ 0 &True \end{cases}$$ No error is reported. $$\begin{cases} 1 &x \geq 0 \\ 0 &True \end{...
3
votes
0answers
105 views

PiecewiseExpand fails with min of two piecewise functions

I have two Piecewise functions that are (in this case) just the empirical CDFs of two sets of data: ...
4
votes
3answers
501 views

Most efficient way to integrate a linear piecewise function

I am having a lot of trouble integrating a simple function. Here's the context: I generate data from two distributions, and I want to calculate the overlap coefficient of representing those datasets ...
3
votes
0answers
105 views

Piecewise and ProbabilityDistribution malfunction when used together

Yesterday I opened this question, what had a happy end after all. But when I tried to model more complex discrete random variables using Piecewise instead of ...
1
vote
2answers
87 views

Piecewise integration fail or something else?

I have a not-so-complicated piecewise cubic function, shown below as the yellow curve on the right. It's derivative is on the left; the blue lines are references. Please see the code below where I ...
3
votes
2answers
87 views

Difference in Piecewise function

I have two piecewise functions that are defined on values of [0,200]. I would like to find out the maximum difference between the two values. The usual Max[] function does not work because all values ...
1
vote
1answer
225 views

Piecewise function created from list

I have a list of values called EDFh3. This contained values which are partitioned by 3 where it is in the format ...
1
vote
1answer
228 views

How to implement a loop inside Piecewise?

I wanna be able to use the Piecewise function such that I don't have to manually enter all the pieces. For example, say I define f[x_]:={x,x^2,x^3} Consider now ...
1
vote
1answer
124 views

DSolve, Simultaneous Eqns + Piece-wise + boundary and initial conditions

mathematica noobie here but could really use some help. So I have 2 sets of equations: 1) w''''[x]=0 and 2) w''''[x]=q[x] 1) has conditions w[0]=0, w'[0]=0 2) has conditions w''[1]=0, w'''[1]=0 1) ...
3
votes
2answers
271 views

Plot of piecewise function is not bounded properly

I am trying to plot a piecewise function that gets bounded above and below a certain value (e.g). ...
0
votes
1answer
103 views

Selecting only list of function output from piecewise function output [closed]

Say I have a piecewise function: V[m_] := Piecewise[{{(1 + m)^2, m >= 1}, {Log[m], m < 1}}] And I input a large list of ...
0
votes
1answer
2k views

Plotting a piecewise function [closed]

I'm having trouble plotting the piecewise function below. The only way I can replicate this function is using ...
0
votes
3answers
324 views

How do I insert a circle inside another circle with Piecewise?

I need to create two circles, where one circle is inside the other using the Piecewise function. So far I have ...
1
vote
1answer
223 views

Variable Increments in a Table

I am working on a problem involving the piecewise function: $$x^2 \quad \mbox{if } \quad x < 2$$ $$(x-3)/(\sqrt{x-2}-1) \quad \mbox{if } \quad x \geq 2$$ I am supposed to find ...
0
votes
3answers
131 views

How I can define this staircase function?

I have a function $f:[-1,1]\to\Bbb R$ defined by $$f(x):=\begin{cases}\frac1{n+2},&x\in\left[-\frac1n,-\frac1{n+1}\right)\cup\left(\frac1{n+1},\frac1n\right]\\0,&\text{otherwise}\end{cases}\...
1
vote
3answers
67 views

Can i use PiecewiseExpand to expand If statements with function arguments?

Usually PiecewiseExpand[] is able to convert If[] statements to Piecewise functions, e.g. <...
1
vote
1answer
120 views

Interpretation of HeavisideTheta Integration Output

I need to integrate integrals of the type Integrate[Boole[2 k*q >= Absolute[p^2 - k^2 - q^2]], q] where $q$, $k$, and $p$ go from $0$ to $1$. To learn to ...
1
vote
1answer
237 views

How to write a piecewise function to take a list of {value,point} as its parameter?

I want to apply Piecewise function to a list of range and values, for example, to make f[{{v1,r2},{v2,r2},{v3,r3},{v4,r4},...,{vn,\[Infinity]}}] generate: ...
0
votes
0answers
172 views

Piecewise defining function, Why do i get extra 0 True? [duplicate]

I have included a picture This happens on every Piecewise function
0
votes
0answers
162 views

Minimize integral with piecewise functions

I am not an experienced user of Mathematica. I would like to find parameters $d1,d2,d3,e1,e2,e3$ which minimize such an integral (given $c11,c12,c13,c21,c22,c23,c31,c32,c33$): $\int_{0}^{1}\int_{0}^{...
4
votes
3answers
183 views

Getting error message when integrating a simple piecewise function

I reviewed the following questions: question 1 and question 2, but I need to the following integral of a piecewise function: ...
1
vote
1answer
182 views

Using Manipulate to Plot a Piecewise Function

I want to plot a piecewise function with two variables using Manipulate command, but I am having trouble with it. The function I want to plot is profit1. (details of the code can be found below) <...
1
vote
2answers
263 views

Calculating probability of piecewise function

I want to calculate the probability of a discrete random variable. First I defined the function: pw = Piecewise[{{1/8, x == 1}, {2/8, x == 2}, {5/8, x == 3}}, 0]; ...
3
votes
2answers
427 views

InterpolatingFunction within Piecewise gives range error?

So I have a function myfun with positive domain that I got from NDSolve and a bunch of transformations afterwards. I can plot it on its own like ...
11
votes
2answers
417 views

StreamPlot No Longer Works With Piecewise Function?

Bug introduced in 7.0.1 or earlier and persisting through 11.1 I was trying to plot a phase portrait (StreamPlot) using a piecewise (...
1
vote
1answer
109 views

Create piecewise f[x,y] from functions with intersecting domains

I have two functions f1 and f2. They have a square region in the $x-y$ plane as their domain. They might intersect, or they ...