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.

310 questions
Filter by
Sorted by
Tagged with
98 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: <...
228 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 ...
645 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: ...
87 views

Trouble solving system of nonlinear equations with piecewise

Here is my code so far ...
521 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 (\...
2k 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.. >...
72 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: ...
236 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 ...
151 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 ...
742 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 ...
411 views

239 views

How to sort the ranges of a Piecewise expression?

I have the following PieceWise expression ...
426 views

Inverse of piecewise function with pieces invertible on specific domain

I have piecewise continuous function defined below: f=Piecewise[{ {15 + 1/6*(# - 3), # <= 27}, {# - 12 + 4 * Exp[-5/24*(#-27)], 27 < #} }]; This ...
475 views

How to enter piecewise functions into Mathematica [closed]

I'm trying to enter a piecewise function (named eq30) into Mathematica. However, it seems not to work. The expression I entered is ...
63 views

NIntegrate a function containing NDSolve

I am having an issue integrating a function for which I am getting values for when I evaluate it. ...
254 views

DSolve with piecewise coefficeints wrong, why?

sorry if this is a duplicate (I am pretty sure) but I was not able to find the question. I am playing around with DSolve with variable coefficients. In the documentation it is said, that DSolve can ...
1k views

Piecewise Function within NDSolve

So I am quite new to Mathematica and programming in general and I am running into an issue while trying to use the numerical diff eq solver (NDSolve) within mathematica. This is what my code looks ...
392 views

Derivative of Continuous and Differentiable Piecewise function is indeterminate

I'm attempting to analytically stitch together two linear functions with two quadratic functions. The function I'm considering, then, is a piecewise function consisting of 4 parts. Below are the ...
385 views

Maximize and NMaximize don't work for my function

I defined the following function: d1[x_] := Min[Abs[FractionalPart[x]], 1 - Abs[FractionalPart[x]]] and tried to evaluate the following function: Maximize[{Min[d1[15*x],d1[12*x],d1[18*x]],Abs[x-...
132 views

Cannot determine, what this partw error message is aiming at …

So i am trying to plot the magnetic vector field surrounding a "flat conducting cable" (don't know the proper english expression). This is the "code" (there are some constants in the analytic ...
603 views

How I can make the StreamPlot of this differential equation?

I need the StreamPlot of this differential equation but I don't know how. dp/dt = 0.4 p(1 - p/30), 0 <= t < 5 and 0.4 p (1 - p/30) - 0.25 p, t > 5
105 views

Fill an array, symmetric with respect to its centre

I want to create an array that must be symmetric with respect to the centre of it, as in the following example: 0 1 2 3 4 3 2 1 but, instead of having such ...
121 views

How to make Piecewise continuous [duplicate]

I have a function defined by its slope in a continuous sequence of intervals, e.g. ...
220 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 ...
393 views

How to draw dots at beginning and end of range when plotting [duplicate]

I'm trying to plot a Piecewise function which should look like this: How can I have similiar dots (filled or empty) at beginning and end of range? ...
358 views

Using parts of piecewise function

I define: f[x_] := Piecewise[{{5, 0 <= x < 10}, {g[x], 10 <= x < 15}, {h[x], x > 15}}] Then I try to solve ODE: ...
515 views

Piecewise ColorFunction for Plot3D

I want to make a 3D plot where the ColorFunction is different depending on whether the function value is positive or negative. I know how to do the following: ...