Python 如何使用sympy查找y截距?
如何使用上面的结构编写一个返回其参数的y截取的函数?尝试使用Python 如何使用sympy查找y截距?,python,math,numpy,sympy,Python,Math,Numpy,Sympy,如何使用上面的结构编写一个返回其参数的y截取的函数?尝试使用sympy.coeff,如下所示: Y截距作为坐标 x = Symbol('x') f = x**2-3 def return_y_intercept(f): return [the y-intercepts] 输出: from sympy import Symbol x = Symbol('x') f = x**2-3 def return_y_intercept(f): return [0,f.coeff(x,0
sympy.coeff
,如下所示:
Y截距作为坐标
x = Symbol('x')
f = x**2-3
def return_y_intercept(f):
return [the y-intercepts]
输出:
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)
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)
Y截距:
0,-3
输出:
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)
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)
在联机Symphy解释器上尝试它尝试使用
symphy.coeff
,如下所示:
Y截距作为坐标
x = Symbol('x')
f = x**2-3
def return_y_intercept(f):
return [the y-intercepts]
输出:
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)
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)
Y截距:
0,-3
输出:
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)
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)
在在线Symphy解释器上试试吧y-截距只意味着用0代替x,所以只需做
f.subs(x,0)
y-截距只意味着用0代替x,所以只需做f.subs(x,0)
这太复杂了。检查另一个答案。@Krasranov这是同样的事情,只是使用sympys内置的coeff
,OP问fo,如何使用sympy找到y截距。但是它只适用于多项式,并且隐藏了代码背后的意图(意图是找到x=0的值;简单的方法是计算它)这太复杂了。检查另一个答案。@Krasranov这是同样的事情,只是使用sympys内置的coeff
,OP问fo,如何使用sympy找到y截距。但是它只适用于多项式,并且隐藏了代码背后的意图(意图是找到x=0的值;简单的方法是计算它)