Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Sketch the graph of the function f(x) = x + |x| on the interval
- # [-2, 2]. Include enough points to make the curve appear smooth.
- # Label the axes x and f(x), and choose an appropriate size for the
- # graph.
- # Define function f
- def f(x):
- return x + abs(x)
- # Plot the function
- # Create an array of x values from -100 to 100
- x = range(-100, 101)
- # Get the corresponding y values from the function
- y = [f(a) for a in x]
- # Set up the graph
- plt.xlabel('x')
- plt.ylabel('f(x)')
- plt.grid()
- # Plot x against f(x)
- plt.plot(x,y, color='purple')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment