Can some please help me?

38 Views Asked by At

Why I am getting nan in python.

from sympy import *
x,f,g=symbols('x f g')

def f(x):
    return (1+x**2)**2
def g(x):
    return (1-f(x))/x
expand(g(x))
g(0)

I know the $x$ is in division but after manual simplification I found $$g(x)=−^3−2$$ and $$g(0)=0$$ I could not understand why python result give me $$g(0) = NaN$$ How can I get g(0)=0 in python.

1

There are 1 best solutions below

0
On

Possible workaround:

from sympy import *
x,f,g,t=symbols('x f g t')

def f(x):
    return (1+x**2)**2
def g(x):
    return expand((1-f(t))/t).subs(t,x)
print(g(0))