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
0
votes
1answer
636 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: ...
1
vote
1answer
32 views

Interpolation of a “bit by bit” Function

I am facing a problem with integrating a function. I have to integrate the function "bit by bit". This is the smallest working example that shows the problem: ...
0
votes
1answer
54 views

Integrating a function “bit by bit”

I am trying to integrate a function. But for this task I need to do it "bit by bit". I created a working example that shows the problem. ...
1
vote
2answers
47 views

How to choose model parameters using `Piecewise` function

The following code (developed by m_goldberg) works as expected. The model parameters can be selected by using Button, being ...
6
votes
4answers
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 ...
3
votes
2answers
128 views

Different colours for different sectors of piecewise function

I have some lines of code that generate numerical solutions to equations. Then I want to combine two of these in a piecewise function. The way I did it is the following -lf1[r] and lf4[r] are the ...
12
votes
2answers
1k views

Solving a discontinuous differential-algebraic equation system for plasticity behaviour

I need to solve a discontinuous equation which is typical in theory of plasticity. For a simple case I get the following equation system (reformulated for numerical implementation): $$\begin{align*} ...
3
votes
1answer
79 views

Reduce to Piecewise

There are some similar posts on SE, but none of them seems to exactly address my issue. I need to integrate a rather complicated function (over $x>1$) separately over two domains defined as ...
6
votes
2answers
138 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 ...
1
vote
1answer
83 views

Piecewise function made up of five segments not showing in a plot [closed]

I want to plot 5 parts in a single graph using a piecewise function. But I am not able to plot the last one. Can anyone please help me with it? The code is as follows. ...
0
votes
1answer
112 views

How to solve transient 3D heat equation with robin boundary conditions

Good afternoon! I'm trying to solve the following heat equation: with the following boundary conditions and initial value: Nut I'm getting error while solving it with NDSolve: ...
3
votes
3answers
58 views

Dots at points of discontinuity

So, I got this code: Plot[Piecewise[{{3, x <= 0}, {x^2 + 1, x > 0}}], {x, -2, 2}, PlotStyle -> {Purple}, Axes -> False, Frame -> True] and I ...
0
votes
0answers
42 views

Plotting discontinuous functions

I want to plot the two roots of a polynomial function. At some value of the variable x, they "swap" and the lines change. However, I want each branch to have te same line style. Is it possible to ...
6
votes
2answers
158 views

The correct way of compute indicator function in Mathematica

$$X_1= \mathbb{1}_{[0,1]} $$ $$X_2= \mathbb{1}_{[0,\frac{1}{2}]}, X_3= \mathbb{1}_{[\frac{1}{2},1]}, $$ $$X_4= \mathbb{1}_{[0,\frac{1}{3}]}, X_5= \mathbb{1}_{[\frac{1}{3},\frac{2}{3}]}, X_6= \mathbb{...
1
vote
1answer
41 views

Having trouble when using a piecewise function

I am trying to define a function where H1[x_]= a previously derived value if 0 < x <100 and H1[x_]=x if x>100 so I have used the following piecewise function: H1[x_]:=Piecewise[{{Evaluate[y[x] /....
3
votes
1answer
107 views

How to set up a Fourier transform?

I am having trouble figuring out how to set up the Fourier transform to: ...
0
votes
1answer
71 views

Extending periodic piecewise continuous function

I need to plot the piecewise function $$ f(x) = \left\{ \begin{array}{r} x^2, & -2 \leq x \leq 0, \\ 0, & 0 < x \leq 1, \\ 1 - x, & 1 < x \leq 3. \\ \end{array} \right. $$ as a ...
0
votes
0answers
20 views

Problem with PiecewiseExpand[Max[ ]]

I have these functions: By running this command: FullSimplify[PiecewiseExpand[Max[a, b , c, x, y, z]], 9 <= \[Beta] <= 11] I obtain: However I think ...
2
votes
1answer
53 views

Maximization of a a PiecewiseExpand funcion

I have the following 3 piecewise functions and their upper envelope. ...
1
vote
1answer
48 views

Find the intervals where a piecewise is maximum

I have the following 3 piecewise functions and I would like to have the threshold of the upper envelope. ...
7
votes
1answer
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 ...
0
votes
1answer
53 views

Piecewise function [closed]

I have the differential equation $$ \omega'(t)= \begin{cases} \frac{1}{J_t}\left(\frac{B}{2}(F_l-F_r)-B_l\omega\right) & \text{if turning=true}\\ 0 & \text{if ...
2
votes
0answers
36 views

How to convert output from Reduce into a piecewise function?

Reduce often provides a much fuller solution than Solve. But it's always in the form of a true statement rather than functions ...
2
votes
2answers
70 views

How to define a discrete distribution with non-integer sample space elements (outcomes)?

How to define a discrete distribution with non-integer states (sample space elements)? I know how to define a discrete distribution with integer states: ...
3
votes
1answer
66 views

elegant definition of piecewise linear functions (spline)

As far as I understand, the Spline object is the result of some approximation or interpolation, it is not for directly defining functions. That's a pity, as that ...
1
vote
1answer
77 views

Piecewise with differential equations

I have the following differential system. The calibration I use is as follows ...
3
votes
1answer
68 views

Piecewise function not evaluating in NDSolve

Perhaps it's something obvious, but why does this simple piecewise function (as well as other conditionals) not evaluate in NDSolve: ...
0
votes
0answers
42 views

Piecewise function to include SawtoothWave function

I am trying to write a Piecewise function that includes the SawtoothWave function. Can someone indicate how to do this, or if it is possible within mathematica? The piecewise code is here: ...
0
votes
1answer
35 views

How does Mathematica solve this 2D piecewise function from constraints?

I am interested in learning the technique(s) used to solve the following 2D piecewise equation for $x, y$ when given $z$, where $z = f(x, y)$. $\text{Given that $x \in \mathbb{Z}$, $y \in \mathbb{Z}$}...
2
votes
2answers
40 views

Piecewise function and deriving - solving

I'm working in a (Economics) problem where I want to add two concave (profit) functions in order to maximize them together through one variable (quantity). My problem is that one of the two functions ...
4
votes
2answers
268 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 ...
1
vote
2answers
49 views

Displaying part of piecewise function

If I define a piecewise function f[t_] := Piecewise[{{t^2, t < 0}, {Sin[t], t > 0}}] Which[f[t], t > 0] how do I display only one part of the function? ...
0
votes
0answers
55 views

Is it possible to unmerge Piecewise expressions?

I have an expression involving Piecewise that I want to break into specific cases. If I let Mathematica's simplification rules loose then it doesn't seem to pick up an obvious cancellation which can ...
1
vote
2answers
41 views

RecurrenceTable of a piecewise recurrence function

How to can I get RecurrenceTable to deal with a piecewise function? For example, $ \qquad x_{n+1}= x_n(1.5-0.5x_n)\qquad \text{if $x_n\ge0.5$}\\ \qquad x_{n+1}= ...
0
votes
2answers
32 views

Piecewise vector

I need to have a vector with the length of 15000. The first 4000 elements have value 12, the next 3000 elements, that is 4001 to 7000 be 0 and the rest of it to the last be 5. I have written it with ...
0
votes
1answer
58 views

Returning a string from a piecewise function

I need to define a function that behaves as a piecewise function, but will return a string instead of a value. Part of the function that I have written is provided below. The full function continues ...
2
votes
2answers
152 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, ...
22
votes
5answers
6k views

Extracting the function from InterpolatingFunction object

I've used Interpolation[] to generate an InterpolatingFunction object from a list of integers. ...
4
votes
2answers
204 views

Heat equation with variable conductivity

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^...
3
votes
3answers
1k views

Why does the first derivative of a piecewise continuous function have discontinuities?

I have this piecewise continuous function which is also continuously differentiable over time : ...
0
votes
3answers
223 views

Using Solve to obtain a constant so that f(x) is continuous at x=2

I need to solve for c such that the function is continuous at x=2. How do I do this automatically? I have expressions for the ...
2
votes
0answers
50 views

Make Mathematica evaluate an integral symbolically

The following integral has a symbolic solution, which MMA does not return. $\kappa(x) \begin{cases} \text{mod}(x,1)\le0.5: & 1\\ \text{mod}(x,1)>0.5: & 0 \end{cases}$ $f(z)=\int_0^1 \...
6
votes
2answers
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 ...
0
votes
2answers
285 views

Fourier series of an arbitrary periodic piecewise function

Let's take a switch function as an example: $ u(t)= \begin{cases} 1, & \text{$0<t<dT_s$} \\ 0, & \text{$dT_s<t<T_s$} \end{cases} $ How can I get Fourier series of it in ...
1
vote
0answers
57 views

Piecewise function inside Integrate - Wrong result

I tried to evaluate the following integral: ...
1
vote
1answer
119 views

Inaccuracy of Piecewise function? [duplicate]

I have the following issue and can't find a solution so far. ...
2
votes
1answer
93 views

Fast and Listable Piecewise function

I am writing a simulation where I have an array with ten columns and on the order of millions of rows, for which I need to iterate on the order of ten thousand times, making computation time a major ...
4
votes
2answers
68 views

How can I make a NumberLineLogPlot'?

I have a piecewise function that is defined in logarithmic intervals, i.e., the different pieces are defined on ...
0
votes
0answers
45 views

Imposing conditions on argument for a function definition

Suppose that I wish to use "Piecewise" to merge two different interpolating functions (obtained via a NDSolve of some ODE), defined over negative and positive arguments respectively, like: ...
0
votes
1answer
60 views

Defining a function with a point of finite discontinuity [closed]

I wrote the code for the function $T$ defined on $[0,1]$ by $T(x)=\frac{x+2}{3}$ if $x\neq\frac{1}{2}$ and $T(\frac{1}{2})=1$ as follows. ...