Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

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
1
vote
0answers
76 views

Obtaining a piecewise polynomial from a plotted parametric curve using splines

Okay, so I have a picture and I have obtained a curve from it using this code: ...
3
votes
1answer
261 views

Extraneous cases in simplified piecewise function

I'm trying to get Mathematica to simplify a piecewise function, but as you can see below it's making some strange errors: I'm telling it i and g are integers, so it ought to know that 2g>4+i is ...
1
vote
0answers
76 views

Problem with NDSolve (and NDSolve) for piecewise definite system

I am using Mathematica 10.4 on Linux system and have the following issue. I have modeled a Dubins car: x, y is its position in the plan and gt, ht is its direction. u is the angular velocity. A basic ...
2
votes
1answer
140 views

Piecewise get value at x [closed]

I have a piecewise function like this. fP = Piecewise[{{x^2, x < 0}, {x, x > 0}}]; Plot[fFu, {x, -2, 2}] Now I want to get the y value at a certain x ...
1
vote
0answers
78 views

Plotting the Full width at half maximum as a function of a parameter

I have this function and I want to plot the FWHM of it as a function of the parameter "a", defined between 0 and 10. It should look like the picture attached. I also put the original equation in case ...
10
votes
2answers
217 views

Problem with Integrate with Piecewise and PrincipalValue

Bug introduced in 8.0.4 or earlier and persisting through 11.3 In the course of developing an alternative solution for question 127301, With, ...
4
votes
1answer
140 views

Piecewise[] merge equivalent conditions

Is there a simple way to merge equivalent conditions in Piecewise? For example, in the following we have (trivially) pw==x. <...
4
votes
1answer
586 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.] ...
2
votes
1answer
259 views

Piecewise function extraction

I have a piecewise function and I'm trying to extract the different functions for different values of the parameter. I use: ...
1
vote
0answers
75 views

Avoiding loops with breakpoints of a Piecewise function

I'm new to mathematica and I'm trying to avoid loops. The setting is the following: I have consumers with preferences (their Betas). Depending on the Beta consumers will have different preferences. ...
1
vote
0answers
283 views

Defining a piecewise function where the conditions are points

I am trying to define the following function in Mathematica: $$pw=\begin{cases} x y \cos \left(\frac{1}{x^2+y^2}\right) & (x,y)\neq(0,0) \\ 0 & (x,y)=(0,0) \end{cases}$$ I want to use this ...
2
votes
2answers
87 views

Derivation of this piecewise function introduces “numerical noise”

The following function is a piecewise function. It's easy to plot with option Exclusions->None but it's derivative is hard to evaluate: ...
1
vote
0answers
79 views

Extracting function names in Manipulate to label plot

I have previously asked a question in regards to determining the labels of the dynamic graph that I have created, but by using SetAttributes and ...
5
votes
2answers
640 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: ...
3
votes
2answers
210 views

Problem with a periodic function and NDSolve

I have defined a periodic function $f(t)$ like this (Mathematica 11): ...
1
vote
2answers
94 views
1
vote
1answer
71 views

symbolic function assignment yields different results than explicit assignment

I am confused as to why the two functions below yield different results (as vs ss)? One function assigns the Piecewise function directly, while the other reads the same function from a list of lists. ...
3
votes
1answer
189 views

Edit piecewise function

Downstream of a long process I got the following function: $\begin{cases} 0 & x < 0 \, \vee \, x > \frac{307}{400} \\ 14.27-7.44\,x & 0 < x < \frac{307}{400} \\ \text{...
0
votes
1answer
107 views

Strange behavior of derivative when using Abs[] [duplicate]

This code where I try to visualize Newton's Method on the function $f(x)=\sqrt{|x|}$ works fine when I define $f(x)$ piecewise. Then why doesn't it work when I define ...
0
votes
1answer
430 views

How to apply a piecewise function to a list? [closed]

I have created this code: xn = {4, -4, 4, -4} f[x_] = Piecewise[{{Sqrt[x], x >= 0}, {Sqrt[-x], x < 0}}] f[xn] With this code I would expect as a result: ...
2
votes
2answers
157 views

Integrate over a piecewise function [closed]

I want to calculate the indefinite Integral of $$f(x)=\begin{cases} 2x\cos(\frac{1}{x})& \text{ if } x\ne 0 \\ 0& \text{ if } x=0 \end{cases}.$$ I use the following code: ...
0
votes
1answer
117 views

Mapping a simple 2 variable function

Quick Question: What is the best way to map this function so it performs seperately for 102 different values of x? ...
2
votes
2answers
619 views

solve system including piecewise function

I've read posts about how to do this in a direct way, but the method doesn't work for my simple system? -- see code: ...
0
votes
1answer
95 views

When does this function equal 'true'? [closed]

I've used Mathematica to find the function $f(t)$ and I found this: Q: What does 'true' say about the function. Is it always equal to $ae^{-\frac{t}{p}}$ or what does it mean?
4
votes
1answer
260 views
2
votes
2answers
333 views

How do I solve Schrödinger equation with a piecewise periodic Hamiltonian? [duplicate]

My Hamiltonian is HI(t) = Piecewise[ {{H1, n τ <= t <= (n + 1/2) τ}, {H2, (n + 1/2) τ <= t <= (n + 1) τ}}] where ...
1
vote
4answers
400 views

Implicitly inverting a function from numerical solution [closed]

I have the following piecewise continuous function: ...
3
votes
2answers
386 views

Switching Differential Equation in NDSolve

I am trying to solve the following system of differential equations using NDSolve: $\dot{z}_t=.5(1-z_t)$ $\dot{y}_t=.05y_t+z_t-x_t$ subject to the following constraint: $-y_t-z_t\le0$ where $z_t$ ...
1
vote
2answers
114 views

Scale in plot and Piecewise

I wrote this code: ...
4
votes
2answers
120 views

Are there any code which just derivative of piecewise function(same distence)?

I wrote this code: Piecewise[{{x^2, 0 <= x <= 1}, {x, x <= 4}}] and I got its derivative with this code: ...
6
votes
2answers
388 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 ...
3
votes
1answer
330 views

Performance of numerical integral over piecewise function

Using mathematica version 10.3, I observe that an integral over a piecewise function evaluates a factor 10 slower than the same integral without the piecewise distinction. Here is the code: ...
-1
votes
1answer
78 views
1
vote
0answers
279 views

NDSolve for an (slightly) discontinuous Piecewise input

I define a Piecewise discontinuous function V[f[t]], which depends on a function f[t] I want to get numerically using ...
5
votes
2answers
1k 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), ...
5
votes
1answer
2k views

How can I combine two Piecewise functions?

I want to be able to combine two piecewise functions. For example, suppose Piecewise1 = f=3 for 1 <=x <=2 and Piecewise2 = f=5 for 1.5<=x<=3, I ...
4
votes
1answer
351 views

Plotting a vector function composed of piecewise scalar functions

I am relatively new to Mathematica, and am having difficulty doing something that is conceptually very simple. I am trying to plot a vector field in which the vector function is composed of piecewise ...
1
vote
1answer
81 views

Plot of a piecewise function misbehaving [closed]

Hi: I am trying to plot a piecewise function. What's weird is that the plot either (a) does not appear at all, or (b) depending on settings, either appears as a horizontal/vertical time. I must be ...
1
vote
0answers
287 views

How to use interpolating functions in NSolve with a piecewise function?

I have a system of two non-linear differential equations that are piecewise, the solutions of which I would like to use to obtain the values of a third variable that is also piecewise. I have trouble ...
1
vote
0answers
77 views

NDSolve with (approximately continuous) Piecewise input

I am finding some troubles when using NDSolve with this piece of code: ...
3
votes
1answer
632 views

NDSolve with an interpolating function in Piecewise

Again I have question I hope someone can answer. I made a very simple example illustrating my more difficult problem. I want to solve a differential equation numerically with a conditional in the ...
1
vote
1answer
386 views

Piecewise function on boundary condition

Consider this initial-boundary-value problem: $$\frac{\partial u}{\partial t}=\frac{\partial^2u}{\partial x^2}+\frac{\partial^2u}{\partial y^2},\quad \Omega=(0,1)\times(0,1),\quad t>0.$$ $$u(x,0,t)=...
8
votes
2answers
511 views

Using OddQ and EvenQ in piecewise functions: Buggy?

I was trying to evaluate a sum over a piecewise function, not unlike this example. However, my piecewise function needed to be defined differently for even and odd ...
3
votes
1answer
262 views

Does 'True' stand for 'Else' in Maximize function output? [closed]

Maximize[a x^2 + b x + c, x] gives this solution: Does the word True stand for "else" here? What exactly did ...
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
0answers
46 views

Obtain a SymmetricReduction of a bivariate (symmetric) function given in Piecewise form

I would like to re-express the following bivariate (symmetric) function (defined over the unit square) ...
-2
votes
1answer
120 views

Manipulate aborts the computation of NDSolve with the Piecewise function after curtain time [closed]

I'm facing the problem with performance: Manipulate is working fine till end time =60 sec, after that it aborts. There is NDSolve inside Manipulate with Piecewise function, and the plot of the ...
2
votes
1answer
735 views

Piecewise Function, Explanation of Extra Case

Consider: Can someone explain why the 0, True occurs? As a second question, I like to fill the endpoints as follows: ...
3
votes
2answers
899 views

How do I find the intersection points of two piecewise functions? [closed]

I've got a piecewise function that is defined as follows: ...
3
votes
2answers
222 views

Plot a parametric function from $\mathbb{R}^2$ to $\mathbb{R}^2$

I want to plot the following function defined on $[-1,1]\times[-1,1]\setminus(0,0)$: $$ F(x,y,t)= \begin{cases} (1-t)(x,y)+t(1,\frac{y}{x})& \text{if}\ -x\leq y\leq x \\ (1-t)(x,y)+t(\frac{x}{y}...