piecewise

Python – Construct a piecewise function using logic

Python – Construct a piecewise function using logic Question: I am currently trying to plot a piecewise function that looks like the following: def kappa_function(x): if (x < 1873): return 120.5 – 0.1488*(x – 273.15)+ (1.554e-4)*(x-273.15)**2 – 9.153e-8*(x – 273.15)**3 + 2.093e-11*(x – 273.15)**4 elif x >=1873: return 42-(x-1873)/70 + ((x-1873)**2)/500000 tempspace = np.linspace(200,10000,10000) kappa_f …

Total answers: 1

np.piecewise generates incorrect values for integer array

np.piecewise generates incorrect values for integer array Question: I have a numpy piecewise function defined as def function(x): return np.piecewise(x, [x <= 1, x > 1], [lambda x: 1/2*np.sin((x-1)**2), lambda x:-1/2*np.sin((x-1)**2)]) I have no idea why this function is returning incorrect values for various x-values. In particular, running the following X = np.array([0,2.1]) Y = …

Total answers: 1

How to Create Piecewise Function in SymPy with Intervals

How to Create Piecewise Function in SymPy with Intervals Question: i need to create a piece-wise function inside an interval but sympy piecewise can’t use and (&). I read that the function can’t recieve Boolean values so I tried to add them together and it doesn’t seem to be right. The code is as follows: …

Total answers: 1

How to apply piecewise linear fit in Python?

How to apply piecewise linear fit in Python? Question: 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 …

Total answers: 12