On Wed, Apr 3, 2019 at 2:47 PM wrote:
> The simplest example:
>
> f = piecewise([[[-pi-1, -pi/2], 0], [(-pi/2,pi/2), 1], [[pi/2, pi+1], 0]])
> print(f(-pi))
>
>
I'm not sure why it isn't evaluating symbolic numbers like pi, but here's a
work-around:
sage: f = piecewise([((-pi-*1*, -pi/*2*), *0*)
The simplest example:
f = piecewise([[[-pi-1, -pi/2], 0], [(-pi/2,pi/2), 1], [[pi/2, pi+1], 0]])
print(f(-pi))
which gives the traceback:
TypeError Traceback (most recent call last)
in ()
> 1 f(-pi)
/Applications/SageMath-8.7.app/Contents/Resources/sage/loca
I have a function g(x) equal to x^2 if x >= 5, and equal to 2*x if x < 5. I
constructed the piecewise function as follows:
g1(x) = x**2
g2(x) = 2*x
g = Piecewise([[(-Infinity,5),g2],[(5,Infinity),g1]])
When I evaluate f(5), it returns 35/2 because it evaluates g1(5), g2(5) and
returns the avera
Piecewise Function: endpoint gotcha - bug or feature?
It seems that the piecewise function (which requires overlapping
endpoints for the specified function intervals) does some unadvertised
averaging for results for values at the endpoints.
See the sage output from the input below.
Rather than p
I'm trying to do something that seems very simple but isn't working.
Hence the post here :)
I want to define a very simple piecewise linear function. It's linear
with slope alpha up to a knot at c and then it's linear with slope
beta. Here's what I thought might work:
f(x) = (x<=c)*alpha*x