Questions about the Piecewise function, which is represented by different expressions for different ranges of values of its independent variable.

learn more… | top users | synonyms

0
votes
1answer
62 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
70 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
56 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?
3
votes
1answer
82 views
2
votes
2answers
127 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
140 views

Implicitly inverting a function from numerical solution [closed]

I have the following piecewise continuous function: ...
3
votes
2answers
106 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
60 views

Scale in plot and Piecewise

I wrote this code: ...
3
votes
2answers
99 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 derivative of this code: ...
5
votes
2answers
195 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
49 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
58 views
0
votes
0answers
63 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 ...
0
votes
0answers
43 views

CForm and Piecewise

I am trying to use Mathematica to evaluate a long function and I would like to export the result to C using CForm. However, my function is a ...
0
votes
0answers
61 views

Problem with piecewise function as source function of NDSolve

It seems that something wrong is with my piecewise source function u[t,x], so I get such an error: ...
5
votes
2answers
150 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), ...
4
votes
1answer
107 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
54 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
48 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
61 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
46 views

NDSolve with (approximately continuous) Piecewise input

I am finding some troubles when using NDSolve with this piece of code: ...
3
votes
1answer
81 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
87 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)=...
5
votes
2answers
137 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 ...
2
votes
1answer
51 views

Does 'True' stand for 'Else' in Maximise function output?

Maximize[a x^2 + b x + c, x] gives this solution: Does the word 'True' stand for 'Else' here?
6
votes
2answers
361 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
28 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
66 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 ...
0
votes
1answer
80 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
107 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
109 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}...
0
votes
2answers
46 views

Plot Piecewise does not work with NDSolve, works with ordinary function [closed]

How to join output from NDSolve with another function in a plot, using Piecewise or something else? I could join a simple function with another in a plot, but could not do it for the output. MWE: <...
0
votes
2answers
72 views

If Which Piecewise-defined function [closed]

How would I write a function using If and/or Which command for following Piecewise-defined function then plot the function ...
4
votes
2answers
164 views

Derivative of piecewise function

I tried to find $f'(0)$ of this function: $$f(x) = \begin{cases} x\cdot\sin(\frac{1}{x}) & \text{if $x\ne0$} \\ 0 & \text{if $x=0$} \end{cases}$$ This is what I tried in Mathematica: ...
0
votes
0answers
43 views
-1
votes
2answers
103 views

Make plot of parametric function with piecewise components

How can I plot this curve in Mathematica: $\begin{align} x(t)&=\begin {cases} 2 (t-n+1) \: , \: t\in [n-1,n-1/2] \\ 2-2 (t-n+1) \: , \: t\in [n-1/2, n] \end {cases}\\ y(t)&=\begin {cases} 2 (\...
2
votes
1answer
321 views

NDSolve with piecewise function gives error “Encountered non-numerical value for a derivative at x == 0.” [duplicate]

I am solving differential equation with piecewise function and i am getting error that NDSolve::ndnum: Encountered non-numerical value for a derivative at x == 0.. >...
2
votes
0answers
43 views

Why does this form of piecewise function cause a general stop message? [closed]

I am currently learning about Mathematica by reading the book Mathematica by Example, 4th Edition. In that book, a piecewise function was defined as follows: ...
1
vote
0answers
50 views

Piecewise in 2D with quadrants as conditions

I am trying to define a piecewise vector field. Can the condition be of the form I am using (i.e. a quadrant)? I can't also make Piecewise work with more than two ...
2
votes
1answer
71 views

NDSolve Dankwerts boundary conditions with changing discrete variable

I'm modeling a advection-diffusion-reaction plug flow reactor (2nd order ODE) at steady state: $$0=-v \frac{\delta p[z]}{\delta z}+D\frac{\delta ^2 p[z]}{\delta z^2}-k p[z]$$ With Dankwerts boundary ...
13
votes
3answers
287 views

Piecewise imposes internal boundaries in NDSolve - is this expected?

In the following code I used True as the predicate for DirichletCondition and found that the boundary condition was applied not ...
6
votes
4answers
241 views

Recursive piecewise integral relation with piecewise base case?

How is this recursive formula $$ f_{n+1}(z) = \int_0^1 f_{n}(z-y)\,{\rm d}y $$ implemented in Mathematica? The base case is $$ f_1(z) = \begin{cases} 1 & 0\leq z\leq 1 \\ 0 & \text{...
4
votes
1answer
117 views

Integration of a piecewise function

Define f[x_, i_] := Piecewise[{{1/n, 0 < x < (i - 1)/n}, {(i/n - x), (i - 1)/n < x < i/n} , {0, i/n < x}} ]; I would like to compute ...
2
votes
0answers
52 views

Mathematica Manipulate, Plot, Piecewise [duplicate]

I have two functions h2 and v2 that I need to graph using Piecewise and be able to ...
2
votes
1answer
99 views

About NDSolve with piecewise inputs

I am trying to solve numerically two differential equations with NDSolve. ...
10
votes
1answer
153 views

Plot3D with Piecewise is Empty [duplicate]

I don't understand what has happened here. Please can someone explain? I start by defining a 2D function and plotting a couple of cases ...
1
vote
0answers
32 views

Piecewise function plots weird when given expression with symbol vs writing it explicitly [duplicate]

The only difference is that in the second snippet the expression is written out explicitly. displacement = (Sin[x - Pi/2 - t] + 1)/2 This doesn't work: ...
2
votes
0answers
63 views

Efficiently summing sets of piecewise linear functions

I am doing a type of permutation test on a collection of continuous piecewise linear functions, which I'm representing in Mathematica using Piecewise. Specifically, ...
-2
votes
1answer
110 views

A piecewise function with way too many pieces

I'm currently calculating a periodic square wave current function to feed into a particle accelerator. It's a square wave that ramps up to a certain frequency and then drops back to the base frequency ...
7
votes
0answers
104 views

Bug in PiecewiseExpand and Mod with assumptions

Bug introduced in 9.0 or earlier and fixed in 10.4 The following code using PiecewiseExpandand Modgives the wrong answer <...