The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
124 views

InterpolatingFunction::dmval error in the Piecewise function with an interpolation funcion included

I have a set of data, first I deal the data with an Interpolation function. excitef1 = Interpolation[ps1] Then I use a Piecewise function to expand the range of ...
17
votes
4answers
741 views

Piecewise imposes internal boundaries in NDSolve - is this expected?

In the following code I used True as the predicate for DirichletCondition and found that the boundary condition was applied not ...
5
votes
3answers
794 views

Colors for multiple piecewise functions

I have the following $3$ piecewise functions, and I would like that f1, f2 and f3 have $3$ ...
3
votes
2answers
92 views

Motion study using initial conditions

I think I'm making a mistake to reach my goal. I would like to find an $x[t]$ function that could describe the following conditions: 1 - The object is in position $x=151$ (meters) at time $t=5$ (...
0
votes
0answers
99 views

Adding advection to a diffusion model

I am attempting to add advection to my mathematica model of 2-D Diffusion. I am trying to add a sine-flow vector field, which is A*sin[x] in the y direction and <...
2
votes
1answer
86 views

Why is Manipulate breaking?

I am trying to manipulate a piecewise function. The first and second piece are attached at point x where x should also be manipulated (basically each curve has it's ...
1
vote
1answer
94 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
139 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 ...
1
vote
2answers
304 views

Integration over a (non-parametric) curve defined by indicator function

I want to integrate the real function myFun defined on a 2D plane over the line locus, defined as the solution of a set of ...
0
votes
1answer
226 views
6
votes
1answer
669 views

Using Boole to integrate over region

I have a complex and long piecewise function to integrate, so I have written a Mathematica script that cuts the whole range of integration, evaluates the integrand in each region and then integrates ...
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
261 views

NDSolve with Piecewise function

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

3D Plotting with Piecewise function

I'm trying to plot the following function: $f(x,y)= \left\{\begin{matrix} (x+y) & (x,y) \in T \\ (x+y)^2 & (x,y) \notin T \end{matrix}\right.$ where $T= \{ y\leq -x+1, x\geq 0, y\geq 0 ...
0
votes
1answer
138 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 ...
0
votes
0answers
96 views

Transform NMinimze into LinearProgramming formulation

I have the following maximization problem that I currently try to solve with Minimize/NMinimize. Unfortunately, this kind of solution method takes really long for large systems of equations and ...
3
votes
1answer
262 views

Does 'True' stand for 'Else' in Maximize function output? [closed]

Maximize[a x^2 + b x + c, x] gives this solution: Does the word True stand for "else" here? What exactly did ...
2
votes
1answer
119 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 ...
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
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 ...
4
votes
4answers
826 views

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 ...
2
votes
2answers
205 views

ContourPlot combined with Piecewise bug

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

Restricting a plot to be over integers

I am trying to plot the following function: ...
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
2answers
2k views

Trying to solve a differential equation with a piecewise initial condition

I am trying to solve $$u_t=\frac{1}{4}u_{xx}$$ $-\infty<x<\infty,\: t>0$ With the initial condition $u(x,0)=\phi(x)$ where $$ \phi(x)= \left\{ \begin{array}{lr} 1 & |x|&...
2
votes
1answer
732 views

Piecewise Function, Explanation of Extra Case

Consider: Can someone explain why the 0, True occurs? As a second question, I like to fill the endpoints as follows: ...
3
votes
1answer
582 views

What does True mean in this case? [duplicate]

I use the following code to find the expansion for small $x$: ...
0
votes
1answer
238 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 ...
32
votes
3answers
4k views

Plot a piecewise function with black and white disks marking discontinuities

Let's say I'd like to plot Sign[x + 0.5]: Plot[Sign[x + 0.5], {x, -1, 1}] Mathematica will give this: This plot does not ...
26
votes
4answers
5k views

Plotting piecewise function with distinct colors in each section

I have a piecewise function that I would like to plot but I was wondering if it is possible that each part of the function that is plotted when its corresponding condition is true be plotted with a ...
2
votes
0answers
81 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
100 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
160 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 ...
6
votes
3answers
396 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
283 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} }]; ...
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}}] ...
5
votes
0answers
88 views

External and internal Assumptions on `PiecewiseExpand` and `Mod`

After this question I'm intrigued about the different behaviors depending where and how the assumptions are given. ...
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 ...
4
votes
1answer
88 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. ...
13
votes
2answers
2k views

Converting ConditionalExpression to Piecewise

I have Solve[] return a list like ...
3
votes
0answers
104 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
104 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: ...
7
votes
1answer
235 views

Slow NIntegrate over complicated domains (sometimes)

This is no longer a problem with Mathematica 10.* where I can use regions to do the integrations Overview I have a very large matrix I need to calculate where each element requires the integration ...
4
votes
3answers
461 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 ...
2
votes
0answers
431 views

Integration of UnitStep or HeavisideTheta

I am using Mathematica 9. If I evaluate Integrate[Piecewise[{{1 - r, r > 0 && r < R}}, 0], r] then I get ...
2
votes
0answers
77 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
102 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: ...
11
votes
2answers
401 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 (...
3
votes
0answers
102 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 ...
7
votes
1answer
2k views

Why does piecewise plot have a discontinuity when the function, first and second derivatives are equal?

There were some related questions to this one, but in this case we have the function value, the first derivative and the second derivative all equal (that was actually the problem I was solving). We ...