Guest User

Untitled

a guest
Jan 8th, 2022
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. # Sketch the graph of the function f(x) = x + |x| on the interval
  2. # [-2, 2]. Include enough points to make the curve appear smooth.
  3. # Label the axes x and f(x), and choose an appropriate size for the
  4. # graph.
  5.  
  6. # Define function f
  7. def f(x):
  8.     return x + abs(x)
  9.  
  10. # Plot the function
  11.  
  12. # Create an array of x values from -100 to 100
  13. x = range(-100, 101)
  14.  
  15. # Get the corresponding y values from the function
  16. y = [f(a) for a in x]
  17.  
  18. # Set up the graph
  19. plt.xlabel('x')
  20. plt.ylabel('f(x)')
  21. plt.grid()
  22.  
  23. # Plot x against f(x)
  24. plt.plot(x,y, color='purple')
  25.  
  26. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment