import numpy as np
from ufl import cofac, sqrt
def f(X):
fx = sqrt(X[0]**2+X[1]**2)
return fx
X = np.array([1.0, 2.0])
Y = f(X)
print(Y)
if f(X)<=3:
f(X)=0.0
print(f(X))
exit()
The above function calculates the distance of a point from the origin. If the distance is less than 3 units, I need to assign the value 0.0 to the function.
But the above code gives me no difference in results before and after the "if" loop. How to assign values to functions inside an if loop?