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

R: piecewise functions & plotting

I am trying to make a composite function consisting of 3 exponential functions: rm(list=ls()) library(mosaic) library(ggplot2) # 3 functions NVent=makeFun(161*exp(-x/51028)~x) # from x [0;259200[ Vent3_4=makeFun(1262*exp(-x/48398)~x) # from x…
Gro
  • 1
  • 2
0
votes
1 answer

Interpreting SymPy.solveset() piecewise results

Really impressed with Sympy's handling the solution of a quartic equation with particularly ugly coefficients. The quartic was solved on a variable I called Tb and the solution had the general form Tb = f(Tc) I did not find much detail in the Sympy…
Larry
  • 3
  • 2
0
votes
1 answer

model fitting with MATLAB

I have a set of measures of signal received power (p) at a given distance (d) and a model with unknown coefficients n1 and n2. What I have to do is find the values of n1 and n2 which minimizes the RMS error. I've seen solutions using lsqnonlin but…
0
votes
1 answer

Integral piecewise function matlab

I am trying to integrate a function F which is defined as: function F x = -3:0.1:3; F = zeros(1, length(x)); for i = 1:length(x) if (1.4<= x(i)) && (x(i) <= 1.6) F(i) = x(i).^2; else F(i) =…
Imran
  • 23
  • 2
0
votes
2 answers

How Do I plot a function that also includes a straight vertical line (such as x=2?)

For my program I'm attempting to have the user input attributes of a cantilever beam and from their input the program would output a shear diagram. I'm starting off simple with a singular downward load (user inputs point on beam where this load…
Kelsey W.
  • 1
  • 1
0
votes
2 answers

Inverse of this piecewise-defined function

I would need to implement the inverse function of the following piecewise-defined function through MATLAB: which is an approximation for Gaussian function. I have already tried using finverse function for each separate piecewise function, however…
ailoher
  • 67
  • 1
  • 13
0
votes
2 answers

How do I perform statements on the dependent variable of a graph in MATLAB?

I would like to know how to grab a specific number from an interval to test it and later be able to built a different functions under one graph. For example (in this case the 'x' variable), x 0:.5:5; Ids=ones(x); figure;hold on; for n = 1:5 …
Y_Y
  • 1,259
  • 5
  • 26
  • 43
0
votes
2 answers

Extracting path coefficients of piecewise SEM (structural equation model)

I'm constructing a piecewise structural equation model using the piecewiseSEM package in R (Lefcheck - https://cran.r-project.org/web/packages/piecewiseSEM/vignettes/piecewiseSEM.html) I already created the model set and I could evaluate the model…
geum
  • 1
  • 1
0
votes
1 answer

Plotting "saw-tooth like" functions on MATLAB

I'm trying to plot a piece-wise function (of the form y = αx + β) on a single plot, such that for different regions on the x-axis, I have different values of α and β for the function. I want to make the locations (on the x-axis) of these steps…
ShinyPebble
  • 135
  • 1
  • 1
  • 10
0
votes
0 answers

Gamma distribution in JAGS - Error in node

I'm trying to parameterise a gamma distribution in JAGS - with a piecewise linear predictor but my model fails to run with the following error message: Error: Error in node (ashape/(aexp(mu[59]))) Invalid parent values The model works when…
Anand Roopsind
  • 581
  • 2
  • 8
  • 11
0
votes
1 answer

Numpy.piecewise not working as intended

In[2]: from numpy import * In[3]: alpha = lambda x: piecewise(x,[x <= 4, 4 < x <= 24, x > 24], [10, 20, 50]) In[4]: print(alpha(5)) 0 In[5]: print(alpha(3)) 10 In[6]: print(alpha(26)) 0 Why isn't this working? there are 3 conditions and 3 functions…
0
votes
2 answers

Matlab plot for many branches (piecewise function)

I want to plot the following function I(x) = 5*(1+x/2) for -2 < x < 0 5*(1-x/2) for 0 < x < 2 0 elsewhere I use the following script: clc; close all; clear all; L = 4; x = -20:1:20; I((-L/2) < x & x<0) = 5*(1 + x/(L/2)); I(0 < x…
User1961
  • 131
  • 8
0
votes
0 answers

Python piecewise poly1d?

Before I attempt to reinvent any wheels, has someone already made a Python class for piecewise polynomials using numpy.poly1d (or the like)? It should take a list of discontinuities and a list of polynomials, and allow all the operations of poly1d,…
0
votes
1 answer

Error in predict.segmented

I was trying to make a prediction using segmented regression and it gives me an Error: "Error in eval(expr, envir, enclos) : object 'U1.Sepal.Width' not found". What am I doing wrong? Here is the sample code: library("segmented") …
Katherine
  • 48
  • 4
0
votes
1 answer

Trouble plotting a piecewise defined function in MATLAB

I'm trying to plot a simple piecewise defined function in MATLAB R2016a. While t is negative, this code should plot v = 0 and when t is positive (or zero), the code should plot v = 10*exp(-5000*t). Here's the code: t = -0.0014:1e-5:0.0014; v =…
Andy
  • 789
  • 8
  • 19