# Questions tagged [piecewise]

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

383 questions
Filter by
Sorted by
Tagged with
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 ...
7k views

### Extracting the function from InterpolatingFunction object

I've used Interpolation[] to generate an InterpolatingFunction object from a list of integers. ...
6k 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 ...
794 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 ...
2k views

### Converting ConditionalExpression to Piecewise

I have Solve[] return a list like ...
701 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 ...
1k views

2k views

### Piecewise differential equation

Say I have a very trivial function $$V\left(r\right)=\begin{cases} -V_{0} & 0\leq r\leq R\\ 0 & r>R \end{cases}$$ with $V_{0}>0$ and $R>0$. I would like to let Mathematica solve ...
456 views

### Alternatives to piecewise

As has been mentioned before, Piecewise causes the Mathematica Kernel to fail to during a NDSolve calculation. How can I write ...
240 views

### How can I use Callout to label the segments of a piecewise function?

When I plot a Piecewise function, I like to put the function name above each part of the plot. I could not find a way to use ...
2k views

### Piecewise Polynomial Interpolation

Given some data pairs $(x_i,y_i)$, with $i=0,...,m$, and a degree $r$, I wish to build a piecewise polynomial function to interpolate these data. That interpolation should be continuous, and, on every ...
179 views

801 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: ...
754 views

### Solving a PDE with its boundary condition expressed as a piecewise function

All I want to do is solve the PDE pde = D[y[x, t], t] + y[x, t] D[y[x, t], x] == 0 with the boundary condition expressed as a piecewise function, say, ...
118 views

### 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: ...
130 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) ...
583 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{...
619 views

### Using units and piecewise functions in Integrate

For simple cases, Quantities appear to be handled well by Integrate: ...
748 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 ...
63 views

...
256 views

### Plotting piecewise functions with distinct colors - issue found [duplicate]

I've been making use of the following thread: Plotting piecewise function with distinct colors in each section A handy feature I found there goes as follows: ...
358 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 ...
634 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.] ...
2k views

### Plotting piecewise functions

I have a list of N functions called functionList. N can be any number. Also, I have a list ...
I have the following $3$ piecewise functions, and I would like that f1, f2 and f3 have $3$ ...
Let us consider the (very simple) problem $\qquad \partial_x[k(x)\,\partial_xu]=0,\quad x\in [0,1]$ $\qquad u(0)=0,\ u(1)=1,$ with $l\in(0,1)$ \$\qquad k(x)=\left\{\begin{array}{l}k_1^{},x<l\\k_2^...