Tag Info

Difference between Piecewise, Which and If?

The main difference is their intended use. Which is a "programming function". It is meant for flow control. It is an equivalent of ...
• 235k

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

Important Update Through a copy-paste mistake, I dropped the temperature dependence on the effective heat capacity, which was the point of the exercise. I have modified the post to correct that ...
• 16.4k

Extracting the function from InterpolatingFunction object

In M11+ you can use the "GetPolynomial" method of an interpolating function to obtain the corresponding piecewise expression (but only when using the default "Hermite" method): ...
• 131k
Accepted

Piecewise-constant function with infinitely many pieces

That $F$ should really be something like $F_n$, defining a family of functions and then your total $F$ would really be the union of the $\{F_n\}$ over the domains where they are non-zero. Then ...
• 46.9k

Piecewise-constant function with infinitely many pieces

"... I need it only as a function of x" ClearAll[f] f[x_] := Min[x - Quotient[x, 2], 1 + Quotient[x, 2]] Plot[f[x], {x, 0, 10}] ...
• 397k
Accepted

...
• 4,999
Accepted

Can one compile the Switch function?

A drawback of the Which command is that it evaluates x repeatedly until one of the conditions of Which is satisfied. This is time consuming when x is a complicated expression or/and when the set of ...
• 235k
Accepted

How to set up a spherically symmetric Fourier transform?

Summary: To perform the 3D Fourier Transform of a spherically symmetric function $f(r)$ in Mathematica, use the command (4 Pi)/k FourierSinTransform[f[r] r, r, k] ...
• 15.2k

Extracting the function from InterpolatingFunction object

You could use Series. What's necessary is to know which abscissa values were used for the interpolation. Let's generate some fake data. ...
• 11.5k
Accepted

StreamPlot No Longer Works With Piecewise Function?

It does seem to be a bug. As a temporary workaround, you can re-express your function in terms of either UnitStep[] or Boole[], ...
Accepted

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

There is a solution to the problem when the value of the function P1[x,t] on the border does not fall to zero, but to a critical value ...
• 45.5k

Extracting the function from InterpolatingFunction object

Here is a (mostly) general routine that (tries to) convert a one-dimensional InterpolatingFunction[] into an equivalent ...
Accepted

...
• 75.2k
Accepted

Alternatives to piecewise

You can use the functions SimplifyPWToUnitStep and SimplifySimplifyUnitStep to convert a ...
• 397k
Accepted

Problem with Integrate with Piecewise and PrincipalValue

I think this is a bug, because if we transform the Piecewise function into a combination of UnitStep (which is mathematically ...
• 66.9k

Piecewise-constant function with infinitely many pieces

One more way is as follows. ...
• 26.7k

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

Inspired by Tim's excellent answer I was wondering if it is not possible to use the FEM for this. In Version 12.0 there is no way to do this from top level. However, we still can solve this phase ...
• 39.9k
Accepted

What does True mean in this case?

From the documentation of Piecewise: The $\text{cond}_i$ are evaluated in turn, until one of them is found to yield True. ...
• 235k
Accepted

RuleDelayed (:>) involving Piecewise leads to Piecewise::pairs warning in ReplaceAll (/.)

While creating the delayed rule Mathematica evaluates the left hand side of the rule by default. Evaluating Piecewise[a_, b___] returns the error message, but stays ...
• 19.1k

How can I plot this piecewise function?

We can use ExclusionsStyle -> {Dashed, AbsolutePointSize[10]} to style the excluded line and its endpoints without having to know where the discontinuities are. ...
• 397k

Extracting the function from InterpolatingFunction object

Instead of trying to come up with a function that replicates the output of the InterpolatingFunction, one could instead "inactivate" it, and then see what kind of ...
• 131k

How to plot a list to look like step function?

The simplest way to make it is ListLinePlot with option InterpolationOrder: ...
• 1,320
Accepted

...
• 397k
Accepted

Converting Piecewise function to C code

-10 < x < 0 // LogicalExpand // CForm (* -10 < x && x < 0 *)
• 66.9k
Accepted

Conversion between Piecewise[] and Abs[] representations

You need PiecewiseExpand, with its second argument being Reals: ...
• 66.9k

How to plot a list to look like step function?

Also, if you have a version 10.2 or above, you could use ListStepPlot Module[ {l}, l = {0, 2, 5, 9, 14}; ListStepPlot[l] ] ...
• 5,969
Accepted

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

Although DSolve cannot solve this problem directly, it can make progress if given some assistance. First consider the corresponding problem with no boundary ...
• 61.6k

Plotting a function discontinuous at one point

Without having to manually look: ...

Continuous non-piecewise equivalent of smoothstep function?

You want a smooth function or bump function, a function with compact support which is infinitely differentiable. An example for a smooth unit step given in the Wikipedia article is ...
• 8,834