''' Plotting Functions In this exercise you will practise how to plot functions with Python. Plotting functions is used, for example, to predict data trends or visualise mathematical results. The first exercise will be done for you as an example. ''' ''' Example: A polynomial function Exercise: Plot the function f(x) = 3x^5 - 2x^2 - 3 in the interval [-1, 1]. Solution steps: 1. Define the function you want to plot. 2. Define the values for the `x`-axis. 3. Calculate the `y`-values using your function. 4. Use matplotlib to visualise the results. Don't forget to give the plot a title and annotate the axes. ''' import numpy as np import matplotlib.pyplot as plt def polynomial(x): # We first define the function to be plotted return 3*x**5 - 2*x**2 - 3 x_axis = np.linspace(-1,1,100) # Define the x-axis within the limits y_values = polynomial(x_axis) # Calculate the y-values plt.plot(x_axis,y_values) # Plot the function plt.title("Plot of a polynomial function") # Give the plot a title plt.xlabel("x-values") # x-axis label plt.ylabel("y-values") # y-axis label ''' Exercise A: A polynomial function - Do it yourself Plot the polynomial function a * x^3 + b for 3 values of `a` or `b`, between -1 and 1. How does your chosen parameter influence the function? ''' # Your code here ''' Exercise B: Two functions in the same plot Take the functions f(x) = 3 - 2x and f(x) = 2 + 3x, plot them in the same plot and find the intersection point by looking at the graph. Determine for yourself the appropriate `x` and `y` bounds such that the point of intersection is easy to read. Remember to add a legend, a title and axis labels. You can add a legend by including `label = "3 - 2x"` in the parameters for `plt.plot()` (so `plt.plot(*plotting parameters*,label = "3 - 2x")`) and then adding a line `plt.legend()`. ''' # Your code here