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
4
votes
2 answers

Piecewise constant or 0-degree spline interpolation in Python/Scipy

Despite scipy's documentation indicating that scipy.interpolate.UnivariateSpline will run on order k<=5, under the hood there is an additional constraint for order >=1. Does anyone know of a way to achieve either 0-degree spline or piecewise…
Benjamin
  • 11,560
  • 13
  • 70
  • 119
3
votes
2 answers

Define a piecewise function with three variables

I am trying to define a function in MATLAB according to the following conditions: If t<0 f(t,x,y)=t*(x/y)+1. else f(t,x,y)=-t*(x/y)+1. end I found a way to define a piecewise function in one variable, but here I have three variables. Is…
Fatimah
  • 169
  • 2
  • 3
  • 10
3
votes
1 answer

Underestimation of f(x) by using a piecewise linear function

I am trying to check if there is any Matlab/Python procedure to underestimate f(x) by using a piecewise linear function g(x). That is g(x) needs to be less or equal to, f(x). See the picture and code below. Could you please help to modify this code…
Juan
  • 2,073
  • 3
  • 22
  • 37
3
votes
0 answers

How to use Excel Solver for piecewise linear fit?

I am trying to use Excel Solver to get fits for a piecewise linear function (here, a three line fit). The Solver explanation here is helpful for a single linear case, but I am not sure how to set the model up "smartly" so that it re-calculates the…
a11
  • 3,122
  • 4
  • 27
  • 66
3
votes
2 answers

Calculating piecewise quantile linear regression with segmented package R

I am looking for a way to obtain the piecewise quantile linear regression with R. I have been able to compute the Quantile regression with the package quantreg. However, I don't want just 1 unique slope but want to check for breakpoints in my…
D_CodeO1
  • 43
  • 5
3
votes
1 answer

Python: piecewise polynomial curve fit in the exponential

I want to reproduce a research result where the distribution is piecewise fitted the following way. ln(y_data) = A(x) : 3rd order polynomial for central part of the fit ln(y_data) = B(x) : 1st order polynomial for both tails of the fit So far, I…
3
votes
2 answers

Broken stick (or piecewise) regression with 2 breakpoints

I want to estimate two breakpoints of a function with the next data: df = data.frame (x = 1:180, y = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0,…
jealcalat
  • 147
  • 9
3
votes
2 answers

Fourier series of Piecewise PYTHON

I tried to find the Fourier Series of With simpy like : p = Piecewise((sin(t), 0 < t),(sin(t), t < pi), (0 , pi < t), (0, t < 2*pi)) fs = fourier_series(p, (t, 0, 2*pi)).truncate(8) But it doesn't seem to work. It is stuck in * (looping?). Is…
alienflow
  • 400
  • 7
  • 19
3
votes
2 answers

How to draw graph of Gauss function?

Gauss function has an infinite number of jump discontinuities at x = 1/n, for positive integers. I want to draw diagram of Gauss function. Using Maxima cas I can draw it with simple command : f(x):= 1/x - floor(1/x); …
Adam
  • 1,254
  • 12
  • 25
3
votes
2 answers

Mathematica piecewise function bad plot rendering

I wanted to plot a user-defined Piecewise function (pagoda function) in Mathematica 10.2. It seems straightforward to me unfortunately the easy command leads to a bad result. My first approach was: f[x_] := Piecewise[{{0, x <= -1}, {-Abs[x] + 1, -1…
roflmaostc
  • 121
  • 6
3
votes
2 answers

creating a function that changes equations at certain slope, usable in curve_fit

I am currently working with fitting decline curves to real-world production data. I have had good luck with creating a hyperbolic and using curve_fit from scipy.optimize. The current function I use: def hyp_func(x,qi,b,di): return…
3
votes
3 answers

AttributeError: 'BooleanFalse' object has no attribute 'evalf' (piecewise plotting using sympy)

I want to plot a piecewise function, such as: import sympy as sym x = sym.symbols("x") f = sym.Piecewise((-1, x < -1), (x, sym.And(-1 <= x, x < 0)), (x**2, sym.And(0 <= x, x < 1)), (x**3, x >=…
Frank King
  • 31
  • 3
3
votes
1 answer

Python: np.vectorize to return "float"

Running the following code: import matplotlib.pyplot as plt import numpy as np def xon (ton, t): if ton <= t: return (t-ton)/5 else: return 0 vxon = np.vectorize(xon) t = np.linspace(0, 49, 50) xontest = vxon(0,…
user_185051
  • 426
  • 5
  • 19
3
votes
1 answer

Crashes with piecewise linear objective for gurobi 6.0.2 / setPWLObj

We have a complex optimization problem which includes several quadratic terms with integer and continous variables (using Anaconda Python / Pycharm with Gurobi 6.0.2). We applied the setPWLObj function to apprixmate the quadratic objective…
3
votes
3 answers

piecewise numpy function with integer arguments

I define the piecewise function def Li(x): return piecewise(x, [x < 0, x >= 0], [lambda t: sin(t), lambda t: cos(t)]) And when I evaluate Li(1.0) The answer is correct Li(1.0)=array(0.5403023058681398), But if I write Li(1) the answer…
yomismo
  • 61
  • 5
1 2
3
24 25