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
28 views

ParametricPlot on Piecewise function not working with consecutive t values [closed]

I am trying to graph a piecewise function composed of a series of parametric cubic functions. I initially created a ParametricPlot for the first four pieces of the equation and it was working fine, as ...
0
votes
0answers
64 views

Fit a three-pulse sequence

I am wondering how to properly fit the three-pulse sequence shown below. I have tried a method which is fitting the three pulses with three polynominal functions seperately and then finding the x-...
5
votes
2answers
103 views

Integration of a piecewise function with parameters

Here is a simple piece-wise and continuous function: f[t_,a_,b_]:=Piecewise[{{a t,t<1},{a,t<1+b},{a(2+b-t),t<2+b}}] When I integrate ...
3
votes
1answer
96 views

Solving Piecewise Differential Equation using NDSolve (coupling at BC)

I am having some issues in dealing with a system of differential equations. I would like to solve a 1D diffusive heat equation across several regions with different material properties. I now have a ...
0
votes
1answer
60 views

Plotting a Piecewise function that returns implicit equations using ContourPlot

I am using ContourPlot to plot implicit equations. Plotting separate implicit equations seems to work fine, however I can't get ContourPlot to plot a piecewise function that returns implicit equations....
1
vote
2answers
54 views

Obtaining the diagonal of Jacobians inside a piecewise function

I have a piecewise function that has in each case an N number of functions that take N arguments. I want to retrieve the diagonals of the Jacobian, or simply the element-wise first derivative of the N ...
1
vote
1answer
43 views

Using assumptions, weird output [closed]

I have a Piecewise function, of the type: $Assumptions = b > a > 0 fun[k_] := Piecewise[{{3k, 0<=k<a}, {k^2, a<=k<=b}}] fun[a] When evaluating ...
3
votes
1answer
45 views

Piecewise function inside If statement or another Piecewise function breaks outputs

I have a calculation that outputs a piecewise function that has as its cases a list of expressions. An example (3 cases with each a list of 4 expressions) is below: ...
3
votes
1answer
60 views

How do I remove part of the plot?

I am in a similar situation as the one described in this post: I need to Plot3D a piecewise function with complicated inequality restriction. I am using this answer ...
1
vote
1answer
37 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
60 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
50 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 ...
3
votes
2answers
129 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 ...
6
votes
2answers
146 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
84 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
125 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 ...
5
votes
1answer
95 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 ...
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 ...
3
votes
1answer
118 views

How to set up a Fourier transform?

I am having trouble figuring out how to set up the Fourier transform to: ...
6
votes
2answers
176 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
42 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] /....
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
56 views

Maximization of a a PiecewiseExpand funcion

I have the following 3 piecewise functions and their upper envelope. ...
1
vote
1answer
49 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. ...
8
votes
1answer
119 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
76 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 ...
4
votes
1answer
58 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
76 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: ...
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 ...
3
votes
1answer
67 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
82 views

Piecewise with differential equations

I have the following differential system. The calibration I use is as follows ...
3
votes
1answer
71 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
36 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
53 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 ...
5
votes
2answers
287 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
51 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
42 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 ...
4
votes
2answers
226 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^...
2
votes
0answers
51 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 \...
0
votes
2answers
322 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: ...
2
votes
1answer
103 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
71 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: ...
1
vote
1answer
73 views

Integrating piecewise function in two variables

I want to find (and plot) the integral of a 'smooth' version of the Möbius function MoebiusMu[x]: ...