I want to be able to define an expression which takes all the values of variable where it is defined and evaluates the expression as 0 when it is not defined. Similar to this: -
import numpy as np
import sympy as sp
def expr(k1, k2):
x, y =sp.symbols('x y')
if x == k1 :
fn = 0
else:
fn = np.divide(1,(x-k1)*(y-k2))
return fn, x, y
f,x, y = expr(1,2)
print(f)
fx = f.subs({x:1,y:4})
print(fx)
So how is the equality or conditionality going to be checked once the function has been defined?
fn = 1/ (x-1)(y-2); How to set it as 0 for x=1 or y=2?