Reputation: 243
x = Symbol('x')
f = x**2-3
def return_y_intercept(f):
return [the y-intercepts]
How is it possible using something like the structure above write a function that returns the y-intercepts of it's argument?
Upvotes: 1
Views: 1970
Reputation: 91580
The y-intercept just means that you substitute 0 for x, so just do f.subs(x, 0)
.
Upvotes: 2
Reputation:
Try using sympy.coeff
, here, so like this:
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)
Output:
0,-3
Y-intercept:
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)
Output:
-3
try it on the online sympy interpreter here
Upvotes: 2