如何使用sympy找到y-intercept?

时间:2012-12-02 02:18:38

标签: python math numpy sympy

x = Symbol('x')
f = x**2-3

def return_y_intercept(f):
   return [the y-intercepts]

如何使用类似上面结构的东西写一个函数来返回它的参数的y-截距?

2 个答案:

答案 0 :(得分:2)

尝试使用sympy.coeffhere,如下所示:

Y-intercept as Coordinates

from sympy import Symbol

x = Symbol('x')
f = x**2-3

def return_y_intercept(f):
   return [0,f.coeff(x,0)] #return coordintes of y-intercept

print return_y_intercept(f)

输出:

0,-3

Y截距:

from sympy import Symbol

x = Symbol('x')
f = x**2-3

def return_y_intercept(f):
   return [f.coeff(x,0)] #return just the y-intercept

print return_y_intercept(f)

输出:

-3

在在线口语翻译here

上试试

答案 1 :(得分:2)

y-intercept只表示你用0代替x,所以只做f.subs(x, 0)