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
6
votes
5answers
1k 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 ...
1
vote
1answer
104 views

Plotting an association key corresponding to the maximum value

I have an Association <|0->q^2, 1->2p q, 2->p^2|>, where q=1-p. I would like to plot the key (0, 1 or 2) ...
0
votes
0answers
207 views

Integral of a step function ,

I am trying to integrate a step function given in a book, but it doesn't work. ...
9
votes
5answers
1k views

Piecewise-constant function with infinitely many pieces

How can I define the following function in Mathematica: $$f(x)=\begin{cases} x-n,&\mbox{when $2n\le x\le 2n+1$,}\\n+1,&\mbox{when $2n+1\le x\le 2n+2$,}\end{cases}$$ where $n$ takes all ...
6
votes
1answer
751 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, ...
0
votes
0answers
158 views

Implicit function: derivative of piecewise function that has a FindRoot in one of the pieces

I have a piecewise function that has as one piece the result of a numerical approximation, like in the example below: ...
0
votes
2answers
241 views

Plotting a piecewise function in Mathematica 10.0

How to I plot the following function in one diagram: from $0$ to $\frac{\pi}{2}$ the function has to equal $\left|\sin\left(x\right)\right|$ and from $\frac{\pi}{2}$ the function $\exp\left(-\frac{x}{...
0
votes
0answers
83 views

FindRoot and piecewise

I want to solve numerically for a variable, let's say x. The equation that defines x has as argument a piecewise function that ...
0
votes
1answer
201 views

Piecewise continuation of a discrete function on an area

I have a discrete function (finite set of values) defined on an area $\Omega$ in $R^2$. Each value of the function is defined on a subarea $\Omega_i$(triangle in my case). These triangles account for ...
0
votes
1answer
462 views

Problem plotting partial sum of a Fourier series

I'm new to using Mathematica, and I have a problem with plotting Fourier series partial sums. In particular, my target is to plot the Fourier series of my piecewise function and with that function ...
1
vote
1answer
243 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 ...
3
votes
2answers
139 views

Very slow code for simulation of optical emission (Raman) spectra

Can anyone help me optimise my code? It currently takes up to 2 hours to run a calculation! I have written a simple code to simulate a type of optical emission spectrum (Raman scattering) for ...
3
votes
2answers
94 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$ (...
2
votes
1answer
787 views

Fourier Transform plot of a piecewise function

I'm working with financial data. I used "Find Formula" to find an approximate function and then I applied FourierTransform to it. Here are the function and the Fourier Transform: ...
0
votes
0answers
118 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
2answers
476 views

Vertical Lines at steps of HeavsideTheta

I want to plot the following: Plot[{Sqrt[x], Sum[HeavisideTheta[x - n^2], {n, 1, Floor[x]}]}, {x, 0,50}] which looks like Is there a simple way to get this same ...
2
votes
1answer
89 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
102 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
164 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 ...
5
votes
1answer
139 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
389 views

NDSolve with Piecewise function

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

Defining a piecewise function with underlying lattice

I'm fairly new to Mathematica, and programming in general, but I'm trying to define an $n$-dimensional piecewise function, $F({\bf x})$. Properties of the function are set by an underlying lattice, ...
0
votes
1answer
191 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 ...
2
votes
1answer
129 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 ...
1
vote
0answers
40 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 ...
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
2answers
268 views

Restricting a plot to be over integers

I am trying to plot the following function: ...
2
votes
2answers
260 views

ContourPlot combined with Piecewise bug

I'm plotting a two dimensional von Mises and Tresca yield surface and got: ...
1
vote
0answers
57 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
1answer
947 views

What does True mean in this case? [duplicate]

I use the following code to find the expansion for small $x$: ...
0
votes
1answer
419 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 ...
2
votes
0answers
98 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
107 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
175 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 ...
2
votes
1answer
396 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} }]; ...
6
votes
3answers
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{...
2
votes
1answer
69 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 ...
3
votes
3answers
104 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}}] ...
4
votes
1answer
124 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. ...
3
votes
0answers
132 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
115 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: <...
2
votes
0answers
95 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
118 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: ...
4
votes
3answers
666 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 ...
3
votes
0answers
121 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 ...
1
vote
2answers
89 views

Piecewise integration fail or something else?

I have a not-so-complicated piecewise cubic function, shown below as the yellow curve on the right. It's derivative is on the left; the blue lines are references. Please see the code below where I ...
3
votes
2answers
99 views

Difference in Piecewise function

I have two piecewise functions that are defined on values of [0,200]. I would like to find out the maximum difference between the two values. The usual Max[] function does not work because all values ...
2
votes
1answer
269 views

Piecewise function created from list

I have a list of values called EDFh3. This contained values which are partitioned by 3 where it is in the format ...
1
vote
1answer
292 views

How to implement a loop inside Piecewise?

I wanna be able to use the Piecewise function such that I don't have to manually enter all the pieces. For example, say I define f[x_]:={x,x^2,x^3} Consider now ...
1
vote
1answer
142 views

DSolve, Simultaneous Eqns + Piece-wise + boundary and initial conditions

mathematica noobie here but could really use some help. So I have 2 sets of equations: 1) w''''[x]=0 and 2) w''''[x]=q[x] 1) has conditions w[0]=0, w'[0]=0 2) has conditions w''[1]=0, w'''[1]=0 1) ...

1 2 3
4
5
8