# Tagged Questions

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

68 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 ...
47 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: ...
77 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: ...
82 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? ...
71 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: ...
58 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?
92 views

...
132 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 ...
142 views

### Implicitly inverting a function from numerical solution [closed]

I have the following piecewise continuous function: ...
110 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$ ...
60 views

### Scale in plot and Piecewise

I wrote this code: ...
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: ...
208 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 ...
55 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: ...
58 views

...
72 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 ...
46 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 ...
62 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: ...
165 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), ...
116 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 ...
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 ...
49 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 ...
62 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 ...
47 views

### NDSolve with (approximately continuous) Piecewise input

I am finding some troubles when using NDSolve with this piece of code: ...
89 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 ...
90 views

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: <...
74 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 ...
174 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: ...
43 views

### Trouble solving system of nonlinear equations with piecewise

Here is my code so far ...
109 views

120 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 ...
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 ...
101 views

### About NDSolve with piecewise inputs

I am trying to solve numerically two differential equations with NDSolve. ...
162 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 ...
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: ...