1

I have the following mathematical function in Python:

y = max(0, |x| - epsilon)

To plot it I have done the usual

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-100,100,400)
y = np.maximum(0, np.absolute(x) - 10)

plt.plot(x,y)
plt.show()

but I want to plot it without assigning any value to epsilon as shown in the picture error func

1
  • What would you want to plot? y is an entire family of functions, one function for each value of epsilon. Looking at it anther way, y is a higher-order function whose limit as epsilon approaches 0 is y = |x|. Commented Apr 8, 2020 at 12:13

1 Answer 1

1

If you know the value of epsilon, then you can do it using plt.xticks:

epsilon = 10
x = np.linspace(-100, 100, 10000)
y = np.maximum(0, np.absolute(x) - epsilon)
plt.figure()
plt.plot(x, y)
plt.xticks([-epsilon, epsilon], ["$-\\varepsilon$", "$\\varepsilon$"])
plt.plot()

If you don't, then you can just determine its value using y:

epsilon = x[y == 0][-1]

And then applying the code above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.