piecewise

Multiple Pieces in a numpy.piecewise

隐身守侯 提交于 2019-12-01 16:06:27
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 take notes with LaTeX, and I'm pretty quick on the python shell, so I figure I can get away with this). The graphs for fuzzy membership functions are highly piecewise, for example: In order to plot this, I tried the following code for a numpy.piecewise (which gives me a cryptic error): In [295]: a = np.arange(0,5,1) In [296]: condlist = [[b<=a<b+0

piecewise function fitting with nls() in R

ぃ、小莉子 提交于 2019-11-30 20:26:16
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, 0.00164402569283353, 0.00128029006251656, 0.00206892841921455, 0.00132378793976235, 0.000953143467154676, 0.00272964503695939, 0.00169743839571702, 0.00286411493120396, 0.0016464862337286, 0.00155672067449593, 0.000878271561566836, 0.00195872573138819, 0.00255412836538339, 0.00126212428137799, 0.00106206607962734, 0.00169140916371657, 0.000858015581562961,

How can I create a piecewise inline function in MATLAB?

孤街醉人 提交于 2019-11-30 19:47:48
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) = { 1.0, 0.0 <= x <= 0.5, -1.0, 0.5 < x <= 1.0 where 0.0 <= x <= 1.0 You really have defined a piecewise function with three break points, i.e., at [0, 0.5, 1]. However, you have not defined the value of the function outside of the breaks. (By the way, I've used the term "break" here, because we are really defining a simple form of spline, a piecewise

How can I create a piecewise inline function in MATLAB?

☆樱花仙子☆ 提交于 2019-11-30 03:59:48
问题 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) = { 1.0, 0.0 <= x <= 0.5, -1.0, 0.5 < x <= 1.0 where 0.0 <= x <= 1.0 回答1: You really have defined a piecewise function with three break points, i.e., at [0, 0.5, 1]. However, you have not defined the value of the function outside of the breaks. (By the

Constructing piecewise symbolic function in Matlab

旧城冷巷雨未停 提交于 2019-11-29 01:57:13
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 <= 1 (1/6)*(-3*x^3+12*x^2-12x+4) -> 1 < x <= 2 (1/6)*(3*x^3-24*x^2+60x-44) -> 2 < x <= 3 (1/6)*(4-x)^3 -> 3 < x <= 4 0 -> otherwise For example, I want to put this function in a variable (let's say f) and then call int(diff(f, 1)^2, x, 0, 4) % numbers could be different and get the (scalar) result 2/3. I tried various things, involving the piecewise()

Fitting piecewise function in Python

只愿长相守 提交于 2019-11-28 12:32:56
I'm trying to fit a piecewise defined function to a data set in Python. I've searched for quite a while now, but I haven't found an answer whether it is possible or not. To get an impression of what I am trying to do, look at the following example (which is not working for me). Here I'm trying to fit a shifted absolute value function (f(x) = |x-p|) to a dataset with p as the fit parameter. import scipy.optimize as so import numpy as np def fitfunc(x,p): if x>p: return x-p else: return -(x-p) fitfunc = np.vectorize(fitfunc) #vectorize so you can use func with array x=np.arange(1,10) y=fitfunc(x

Why is there no piecewise tuple construction?

白昼怎懂夜的黑 提交于 2019-11-27 17:31:07
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 is, if the types T1 and T2 can be constructed from a set of arguments a1, a2, ... and b1, b2, ... , then morally speaking we can make a pair "pair<T1, T2> p(a1, a2, ..., b1, b2, ...)" directly. Practically, this is spelt out as something like this: std::pair<T1, T2> p(std::piecewise_construct, std::forward_as_tuple(a1, a2, ...), std::forward_as

Why is there no piecewise tuple construction?

百般思念 提交于 2019-11-26 22:34:21
问题 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 is, if the types T1 and T2 can be constructed from a set of arguments a1, a2, ... and b1, b2, ... , then morally speaking we can make a pair "pair<T1, T2> p(a1, a2, ..., b1, b2, ...)" directly. Practically, this is spelt out as something like this

How to apply piecewise linear fit in Python?

夙愿已清 提交于 2019-11-26 19:46:31
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 numpy as np x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,11, 12, 13, 14, 15]) y = np.array([5, 7, 9, 11, 13, 15, 28.92, 42.81, 56.7, 70.59, 84.47, 98.36, 112.25, 126.14, 140.03]) def linear_fit(x, a, b): return a * x + b fit_a, fit_b = optimize.curve_fit(linear_fit, x[0:5], y[0:5])[0] y_fit = fit_a * x[0:7] + fit_b fit_a, fit_b = optimize.curve_fit

How to apply piecewise linear fit in Python?

ぃ、小莉子 提交于 2019-11-26 06:28:36
问题 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 numpy as np x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ,11, 12, 13, 14, 15]) y = np.array([5, 7, 9, 11, 13, 15, 28.92, 42.81, 56.7, 70.59, 84.47, 98.36, 112.25, 126.14, 140.03]) def linear_fit(x, a, b): return a * x + b fit_a, fit_b = optimize