Questions tagged [piecewise]

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

315 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 ...
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 ...
6k views

Extracting the function from InterpolatingFunction object

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

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 ...
109 views

Converting Piecewise function to C code

I'm trying to convert a function to C Code f = D[Piecewise[{{x^2, -10 < x < 0}, {x, x > 0}}], x] I decided to scan through conditions and corresponding ...
239 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 ...
914 views

Plotting a function discontinuous at one point

I am trying to plot a function which has a discontinuity at one precise point. However, when I naïvely use Plot with this function the discontinuity point does not seem to be taken into account. For ...
394 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 ...
1k 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 ...
140 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 ...
571 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 ...
160 views

116 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: ...
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{...
596 views

Using units and piecewise functions in Integrate

For simple cases, Quantities appear to be handled well by Integrate: ...
679 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 ...
235 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: ...
594 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.] ...
1k views

Plotting piecewise functions

I have a list of N functions called functionList. N can be any number. Also, I have a list ...
804 views

Colors for multiple piecewise functions

I have the following $3$ piecewise functions, and I would like that f1, f2 and f3 have $3$ ...
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 ...
653 views

Defining a piecewise function from a sequence of functions [closed]

I'm attempting to define a piecewise function from a sequence of defined functions. I've attempted something like this: ...
2k 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), ...
1k views

Integrate over piecewise function defined using /;

f[x_] := x /; x<0 f[x_] := x^2 /; x>=0 Integrate[f[x],{x,-1,1}] The above does not work (Mathematica returns it unevaluated), but the below does. <...
448 views

Creating a function with integral zeroes of the 0th, 1st, and 2nd derivatives

I would like to be able to randomly generate functions, each of which satisfies $f : [-10, 10] \rightarrow [-10, 10]$ All the zeroes, critical points, and inflection points have an integral $x$-...