ubsuny / 23-Homework6G3

This is the main repository for 23-Homework6G3 involving calculus.
https://github.com/ubsuny/23-Homework6G3
Apache License 2.0
0 stars 7 forks source link

How I dealt with singularities #45

Closed AhmedCode99 closed 10 months ago

AhmedCode99 commented 10 months ago

In order to avoid dividing by zero, I used the following:

def f(x):
# Replace zero values in x with a small positive value to avoid division by zero
x_safe = np.where(x == 0, np.finfo(float).eps, x)
return np.exp(-1 / x_safe)

It works perfectly. Feel free to use it.