So I create a piecewise function like this:
x= sp.symbols('x')
f = sp.Piecewise(
(1, x==0),
(sp.sin(x)*(x+1)/x, True))
but if i substitude x with 0 I'll get nan:
f.subs(x,0)
nan
So 1st question is why == doesn't work well with sympy.Piecewise?
Well, I change it to that:
f = sp.Piecewise(
(sp.sin(x)*(x+1)/x, sp.And(x < 0, x > 0)),
(1, True))
And it works kinda.
Next thing I'd like to do is to calculate a derivative of the function using it's definition in x = 0: I need to calculate a limit:
So I far as I need to calculate it in x = 0, I code this:
Δx = sp.symbols('Δx')
expr = f.subs(x, Δx)/Δx
sp.limit(expr, Δx, 0)
But it outputs oo which means infinity. And that's kinda not true, cuz if I call diff function, I'll gain 0, which is kinda true(at x = 0 the derivative of f is 0):
sp.diff(f, x).subs(x,0)
0
Can someone tell me what's wrong with my code and how can I correct it. Thanks.