# Questions tagged [piecewise]

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

88 questions
Filter by
Sorted by
Tagged with
11k views

### Extracting the function from InterpolatingFunction object

I've used Interpolation[] to generate an InterpolatingFunction object from a list of integers. ...
• 493
5k 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 ...
• 474
7k 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 ...
• 403
4k views

### Can NDSolve handle discontinuous data?

Backslide introduced in 9.0, persisting through 11.0.1 It is possible to numerically solve a differential equation if not-smooth data are involved? For example the following instruction return the ...
• 7,133
1k views

### Solving Stefan's solidification problem - for the case of 3 regions

This question heavily related to this question, where the case of two PDE's are solved along with a zipping condition that is a function of time. Using the link in the code I have solved this set of ...
• 397
1k views

### 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 ...
• 4,885
5k views

### Fitting piecewise functions

I have several large data sets which follow the following pattern: A position is measured, a force is applied until a new equilibrium is found. I'd like to find a fit for the position, at least at the ...
• 8,627
2k 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: ...
• 15k
646 views

### How to display the support $\mathrm{supp}(f)$ of a piecewise function $z = f(x,y)$?

I'm wondering how to display the support $\mathrm{supp}(f)$ of a piecewise surface $z = f(x,y)$. As an example, let's consider the following piecewise function (and plot it): ...
• 235
502 views

### Why does plot not show where Piecewise function is not zero?

From my user point view this looks like bug. But I am not an expert. f[x_?NumericQ]:=Piecewise[{{1,x==1},{0,True}}]; Plot[f[x],{x,0,1}] Does not show ...
• 148k
2k views

### Difference between Piecewise, Which and If?

I have the impression that these functions have different evaluation rules. I cannot produce a minimal example right now, but in general, what are the differences between these functions? That is, ...
• 11.4k
991 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 ...
• 85.2k
1k views

### Using OddQ and EvenQ in piecewise functions: Buggy?

I was trying to evaluate a sum over a piecewise function, not unlike this example. However, my piecewise function needed to be defined differently for even and odd ...
• 250
926 views

### Transform Piecewise[] into sum of indicators

I'm interested in transforming a piecewise defined function into a sum of indicator functions, ultimately with the aim to be better able to integrate them. As an example I would like to transform the ...
• 83
301 views

### Piecewise[] merge equivalent conditions

Is there a simple way to merge equivalent conditions in Piecewise? For example, in the following we have (trivially) pw==x. <...
• 16.8k
431 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 ...
• 283
1k views

• 8,798
361 views

### Best 5 segment piecewise linear fit

I'm trying to get a piecewise linear best-fit for the closing price of one of the stocks I'm interested in. The logic seems ok, and the workflow works for a straight-line (ie 2 pts, ie 1 segment) ...
1k views

### Derivative of piecewise function

I tried to find $f'(0)$ of this function: $$f(x) = \begin{cases} x\cdot\sin(\frac{1}{x}) & \text{if x\ne0} \\ 0 & \text{if x=0} \end{cases}$$ This is what I tried in Mathematica: ...
• 2,341
3k views

### Derivatives of piecewise functions of functions

Background Derivatives of piecewise functions in Mathematica are computed according to special rules. According the Piecewise documentation (see Possible Issues), ...
• 3,447
109 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. ...
• 36.9k
5k views

### Plot Even Piecewise function

Is it possible in Mathematica to plot an even piecewise function like: $f(x) = \begin{cases} 3t , 0 \le t \le \frac{\pi}{2} \\ 3t + 6 , \frac{\pi}{2} \le t \le \pi \end{cases}$ which has ...
• 335
763 views

### Can one compile the Switch function?

I am aware that one can compile Which, e.g.: ff = Compile[x, Which @@ {x < 0, 2, x >= 0, 3} ff[1.] ...
• 795
2k views

798 views

• 6,767
616 views