Questions tagged [piecewise]

"piecewise" may refer to a piecewise function, a piecewise interpolation or a piecewise regression / smoothing.

Defining a piecewise function normally requires writing if ... else ... clause.

Interpolation is inherently piecewise.

Piecewise regression often refers to piecewise linear regression, or segmented regression.

367 questions
3
votes
3 answers

Maxima - differentiating a piecewise function

Suppose you have a function defined by intervals, such as f(x):=block(if x<0 then x^2 else x^3); When we differentiate it with diff(f(x),x); we get d/dx (if x<0 then x^2 else x^3) whereas I'd like to get (if x<0 then 2*x else 3*x^2) Is there a…
mmj
  • 5,514
  • 2
  • 44
  • 51
3
votes
5 answers

Interpolating 2d data that is piecewise constant on faces

I have an irregular mesh which is described by two variables - a faces array that stores the indices of the vertices that constitute each face, and a verts array that stores the coordinates of each vertex. I also have a function that is assumed to…
D R
  • 21,936
  • 38
  • 112
  • 149
3
votes
1 answer

How to code a piecewise function in R for a little simulation and store values in a data frame

I need to put in code a piecewise function and store generated values in a data frame. The rules are the following: I have an object X that is generated by a Bernoulli(1/3). If X=0, another object, Y, is generated by E = Exponential(1). If X=1, Y…
anxoestevez
  • 190
  • 2
  • 18
3
votes
1 answer

Numpy's Piecewise Function

Consider this snippet of code: from numpy import * from pylab import * #set up constants v_f = 4.6e5 l = 1.e-9 c = 3.0e8 g = 4*2*pi mu_B = 9.27e-24 hbar = 1.05e-34 m = 9.e-31 alpha = v_f*hbar e = 1.6e-19 eps = 8.85e-12 #epsilon_0 B = arange(2.5,…
Anthony
  • 133
  • 4
2
votes
1 answer

How to "embed" Piecewise in NDSolve in Mathematica

I am using NDSolve to solve a non-linear partial differential equation. I'd like one of the variables (Kvar) to be a function of the time step currently being solved and hence and using Piecewise. Mathematica generates an error message…
dearN
  • 1,256
  • 4
  • 19
  • 40
2
votes
1 answer

emtrends and piecewise regression

I want to obtain four slopes for piecewise regression. Two slopes for each release type before 365 days, and after 365 days. I also know I should use the emmeans package. Here is a dummy dataset. df <- data.frame (tsr = c(0,0,9,10,19,20,20,21,…
Rnoobie
  • 139
  • 7
2
votes
0 answers

How to fix piecewise regressions plots whose lines do not match the segments? ggplot2 and segmented packages?

I did piecewise regressions, found the breakpoints and plotted following this example. According to the results, there is only one breakpoint at 107.4733, so 2 lines are expected to be presented: one before and one after this value of x. However,…
Daniel Valencia C.
  • 2,159
  • 2
  • 19
  • 38
2
votes
0 answers

generate a new piecewise function based on a number of piecewise functions in python

suppose I have a few lists b_wi = [[1,2],[1.5,2.5,3]] #b_wi is a subset of x f_wi = [[5,4,2],[1,1.8,3,9]] the following two are step functions formed by the above lists. ''' F1 = f_wi[0][0] if x< b_wi[0][0] ; f_wi[0][1] if b_wi[0][0] <=x<…
G-09
  • 345
  • 2
  • 13
2
votes
1 answer

Can I use interaction terms with psem in piecewiseSEM?

I am trying to use interaction terms with psem in the piecewiseSEM package but I get the following error: Error in names(B) <- numVars : 'names' attribute [3] must be the same length as the vector [2] lme(response1 ~ predictor1 * predictor2,…
user3508884
  • 75
  • 1
  • 1
  • 8
2
votes
1 answer

How can I get a piecewise function with sympy when some parameter is unknown?

I wonder if there is a way to specify that p is greater than 0 and smaller than pi, so that I don't get "cannot determine truth value of Relational".
ramhuw
  • 61
  • 3
2
votes
1 answer

How to initialize 2D-discontinuous initial data in pyhthon

I've just coded my finite difference solver in Python for the heat equation in the unit square, and in order to check an important property of the equation I need to give as initial data a discountinuous function. My domain in [0,1] x [0,1] and I'd…
slamWolfen
  • 43
  • 4
2
votes
1 answer

Conditional Piecewise function in a set of differential equations

I am trying to implement a model, and I have this conditional Piecewise function, as part of the model. where T_zone(=293) and T_in(=348) are previously defined constants, x2 and x5 are variables dependent on other equations that depend on T_in…
2
votes
0 answers

Are there any Python options for 3D linear piecewise/segmented regression

I'm looking for a solution to fit a number of piecewise planes to linearly approximate a surface. Ideally the user could define the number of planes and the code would determine the "optimal" pieces of the data to fit them to. There seems to be a…
james
  • 41
  • 2
2
votes
1 answer

Segmented regression in python using differential evolution

I have the long-term aim of creating a module that for a specific data set, fits segmented regressions up to an arbitrary number of breakpoints, as well as a standard polynomial and linear curve fit, and then evaluates which of the fits are the most…
2
votes
1 answer

Piecewise regression : davies.test returns p-value = NA

My data : require(segmented) cp <- c(0.079, 0.079, 0.079, 0.080, 0.080, 0.081, 0.081, 0.081, 0.081, 0.081, 0.081, 0.082, 0.083, 0.084, 0.086, 0.088, 0.088, 0.088, 0.088, 0.088) dates <- c(1443991015, 1443994615, 1443998215, 1444001815, 1444005415,…
Loulou
  • 703
  • 5
  • 17