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
0
votes
1 answer

np.piecewise does not work with three conditions

i am very new to python and need to define a piecewise funtion, however, as soon as i specify more than two conditions i am greeted with "ValueError: function list and condition list must be the same". For example, the very basic test function def…
Xeno
  • 1
  • 2
0
votes
1 answer

How to include piecewise defined functions in bvp4c solver in Matlab

I am having trouble using the bvp4c with piecewise defined functions. I tested the code and it works fine when the piecewise defined functions are constant. The problem is that I get wrong results in the graph (that I know for sure) in the area…
SuzieQ
  • 1
  • 1
0
votes
0 answers

How to include a piecewise function in the dsolve command-MATLAB?

I am looking for a way to include piecewise functions in the dsolve command in order to solve a 2nd order differential equation. Dsolve works fine if H(x),G(x),F(x) are constant, but I need them to become piecewise symbolic functions. Thanks. (for…
SuzieQ
  • 1
  • 1
0
votes
1 answer

Summation of piecewise functions in matlab

I have function y, whish is the sum of piecewise functions f0_basis and f1_basis (defined on [r_i-1; r_i+1]), multipled by number coefficients alpha and beta: y=@(r) 0; for j=1:1:N y1= @(r) f0_basis(r ,j).*alpha(j)+f1_basis(r ,j).*beta(j); …
Feels Good Man
  • 113
  • 1
  • 7
0
votes
0 answers

Segmented multiple regression in SAS

I would like to do a segmented multiple regression with fixed effects (with and without interactions). Does SAS has any procedures to handle this task. I've read the PROC NLIN can do a segmented regression, however I can only find tutorials on a…
Mai Pham
  • 1
  • 1
0
votes
1 answer

piecewise linear interpolation in R

I understand you can use approx function to linearly interpolate. However, I could not find anywhere how to piecewise linearly interpolate the pair of points. For instance, assume x<-c(1,4,3,2) y<-c(4,3,2,1) Can anybody give me an answer? Thanks a…
BJKIM
  • 11
  • 1
0
votes
1 answer

How to use R to solve a program with piecewise constant objective function?

I would like to solve a minimization problem using R that has a piecewise constant objective function. The idea is that for lower values of my (integer) decision variable x higher penalty costs are incurred than for higher values. I want to minimize…
Braamstruik
  • 211
  • 2
  • 11
0
votes
0 answers

Piecewise HLM model using nlme package in R

I have two time periods of interest and four observation points(0 months, 4 months, 12 months, 16 months) for my subjects. The first time period of interest is between observation 1 and observation 3. The second time period of interest is between…
user61578
  • 1
  • 1
0
votes
1 answer

Solving a piecewise function for a given intercept in Matlab

I'm trying to solve a piecewise function, but I am getting an error. The following is the code. script: syms x y_intercept = 2; answerr = solve(pw_f(x) == y_intercept, x); piecewise function (in a separate file within the same folder): function y…
0
votes
0 answers

R Piecewise Function Plotting

So I read an answer here and then went ahead to define a piecewise function using ifelse. I have a piecewise function defined to illustrate the penalty dollar amount p of not insuring to value at different loss amounts of x dollars. p <-…
fika_fika
  • 111
  • 1
  • 10
0
votes
1 answer

Convert a python list into function

I am doing some numerical analysis whereby I have a series of python lists of the form listn = [1, 3.1, 4.2] I want to transform these into functions mapped onto a domain between x_0 and x_1, so I can pass the function object to a higher order…
user3684792
  • 2,542
  • 2
  • 18
  • 23
0
votes
0 answers

How to draw a self-definition piecewise function using ifelse

f = function(x) { y <- rep(0, length(x)) y <- x[x >= 0 & x < 1] y <- 2 - x[x >= 1 & x < 2] return(y) } Here is one way I used to get plot of piecewise function f. How to use command ifelse to get a plot of f(x)?
0
votes
1 answer

Error in segmented regression for three covariates and two breakpoints in R

I am trying to estimate the breakpoints for a variable V with three covariates (X,Y,Z) and two breakpoints. The response variable V = aX + bY + cZ + d I simulate the data where (a,b,c,d) have 3 sets of values as (0.6,0.2,0.8,0.15),…
0
votes
0 answers

Define piecewise linear function in R, call function from a list of functions

I have been looking for a solution for a long time but still didn't get it to work. I'm very grateful for every helpful suggestion! I am trying to define a piecewise linear function in R, this means, I want to define a function that has different…
Sunny
  • 11
  • 2
0
votes
0 answers

Generate number from a piecewise exponential distribution

I would like to generate a random number from a piecewise exponential distribution, which has different hazard rates at different time-intervals. What I understood is that it is possible to apply the memoryless property of the standard exponential…