Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Basic python question Define a function plot_polynomial( xs, ys, degree, color )

ID: 3774996 • Letter: B

Question

Basic python question

Define a function plot_polynomial( xs, ys, degree, color ) that takes in two lists of coordinates, a degree, and a string representing plot color.

This function should:

Call polynomial_fit( xs, ys, degree ) to get fitted_ys.

Plot the given xs and ys with using a dot marker for the given color.

Plot fitted_ys on xs with lines of the given color.

Example Usage:
>>> xs = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
>>> ys = [ 4, 7, 12, 16, 10, 10, 9, 15, 17, 19, 10, 8, 6, 5, 2, 1]
>>> plot_polynomial(xs, ys, 5, 'b')
>>> plt.show()

~a graph pops up as well that is 20 high, 16 wide, has a hill like line running through with random dots

Explanation / Answer

import numpy as np
import matplotlib.pyplot as plt
def plot_polynomial(xs, ys, degree, color):
    polynomial = np.poly1d(np.polyfit(np.array(xs), np.array(ys), degree))
    plt.plot(polynomial(xs),ys,color)
    plt.show()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote