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
86
votes
12 answers

How to apply piecewise linear fit in Python?

I am trying to fit piecewise linear fit as shown in fig.1 for a data set This figure was obtained by setting on the lines. I attempted to apply a piecewise linear fit using the code: from scipy import optimize import matplotlib.pyplot as plt import…
Tom Kurushingal
  • 6,086
  • 20
  • 54
  • 86
51
votes
2 answers

C++11 use-case for piecewise_construct of pair and tuple?

In N3059 I found the description of piecewise construction of pairs (and tuples) (and it is in the new Standard). But I can not see when I should use it. I found discussions about emplace and non-copyable entities, but when I tried it out, I could…
towi
  • 21,587
  • 28
  • 106
  • 187
43
votes
3 answers

Why is there no piecewise tuple construction?

The standard templates std::pair and std::array are special cases of std::tuple, and it stands to reason that they should have a very similar set of capabilities. However, uniquely among the three, std::pair allows for piecewise construction. That…
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
22
votes
3 answers

Piecewise regression with R: plotting the segments

I have 54 points. They represent offer and demand for products. I would like to show there is a break point in the offer. First, I sort the x-axis (offer) and remove the values that appears twice. I have 47 values, but I remove the first and last…
Antonin
  • 1,748
  • 7
  • 19
  • 24
11
votes
2 answers

Constructing piecewise symbolic function in Matlab

I am trying to generate a piecewise symbolic function in Matlab. The reason it has to be symbolic is I want to be able to integrate/differentiate the function afterwards and/or insert actual values. I have the following function: x^3/6 -> 0 < x…
Maximilian Csuk
  • 584
  • 1
  • 6
  • 21
10
votes
3 answers

Define Piecewise Functions in Julia

I have an application in which I need to define a piecewise function, IE, f(x) = g(x) for [x in some range], f(x)=h(x) for [x in some other range], ... etc. Is there a nice way to do this in Julia? I'd rather not use if-else because it seems that…
user3587051
  • 473
  • 6
  • 13
9
votes
2 answers

Extrapolate from triangulation

Suppose we have five vertices: X = [0 1; 2 1; 4 1; 1 0; 3 0]; a triangulation: T = [1 4 2; 4 5 2; 5 3 2]; and function values defined on the vertices: Fx = [1; 2; 3; 4; -5]; then we can easily…
Paul
  • 766
  • 9
  • 28
8
votes
1 answer

Piecewise linear fit with n breakpoints

I have used some code found in the question How to apply piecewise linear fit in Python?, to perform segmented linear approximation with a single breakpoint. The code is as follows: from scipy import optimize import matplotlib.pyplot as plt import…
Erlend Vollset
  • 103
  • 1
  • 9
8
votes
1 answer

Multiple Pieces in a numpy.piecewise

I am taking a course on Fuzzy Systems and I take my notes on my computer. This means that I have to draw graphs on my computer from time to time. Since these graphs are quite well defined, I feel that plotting them with numpy would be a good idea (I…
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
8
votes
2 answers

how to specify a range in numpy.piecewise (2 conditions per range)

I am trying to construct a piecewise function for some digital signal processing, but I cannot get numpy.piecewise to allow me to specify a range. Here is what I want to input: t = np.arange(-10,10,1) x = lambda x: x**3 fx = np.piecewise(t, [t < -1…
Pswiss87
  • 725
  • 1
  • 6
  • 16
7
votes
4 answers

How can I create a piecewise inline function in MATLAB?

I have a function in MATLAB which takes another function as an argument. I would like to somehow define a piecewise inline function that can be passed in. Is this somehow possible in MATLAB? Edit: The function I would like to represent is: f(x) = {…
Scott
  • 2,551
  • 5
  • 25
  • 25
7
votes
4 answers

piecewise function fitting with nls() in R

I am trying to fit a two-part line to data. Here's some sample data: x<-c(0.00101959664756622, 0.001929220749155, 0.00165657261751726, 0.00182514724375389, 0.00161532360585458, 0.00126991061099209, 0.00149545009309177, 0.000816386510029308,…
FGiorlando
  • 1,121
  • 2
  • 12
  • 22
6
votes
6 answers

How to define a piecewise function in R

I want to define a piecewise function using R, however, my R code goes wrong. Any suggestion is welcome. x<-seq(-5, 5, by=0.01) for (x in -5:5){ if (-0.326 < x < 0.652) fx<- 0.632 else if (-1.793
Frank Wang
  • 1,462
  • 3
  • 17
  • 39
6
votes
2 answers

how to generate a random convex piecewise-linear function

I want to generate a toy example to illustrate a convex piecewise linear function in python, but I couldn't figure out the best way to do this. What I want to do is to indicate the number of lines and generate the function randomly. A convex…
belcansi
  • 88
  • 5
6
votes
1 answer

How to use ggplot2 to plot results from 'segmented' package?

I followed these steps to plot the results of a piecewise linear regression with one breakpoint which I have done by segmented package: lin.mod <- lm(ChH~CL) segmented.mod <- segmented(lin.mod, seg.Z=~CL) data1 <- data.frame(x = CL, y = ChH) data2…
EKp
  • 83
  • 1
  • 7
1
2 3
24 25