Question

P1 This project requires you to solve the following problems. Some problems may require the use of a computer. It will be indplease make sure the answer is correct %100

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • There are 6 data points given. We can fit a 5th degree polynomial on the points. This polynomial will have 6 coefficients.
  • The 6 coefficients can be obtained with numpy's polyfit method.

program logic:

  • Define the data points x and y as vectors.
  • pass the vectors to polyfit() function and obtain the coefficients in an array p.
  • plot the x,y datapoints and the fit to check the approximation.

program:

Note: documentaion of the code is provided in comments

import numpy as np
import matplotlib.pyplot as plt

x = [1,2,3,4,5,6]
y = [2,5,9,12,21,35]

#there are 6 data points
#it is possible to fit a 5th degree polynomial
#the fit will produce the coefficients as output

p = np.polyfit(x,y,5)
#x[0]**n * p[0] + ... + x[0] * p[3] + p[4] = y[0]
#x[1]**n * p[0] + ... + x[1] * p[3] + p[4] = y[1]
#...
#x[5]**n * p[0] + ... + x[5] * p[3] + p[4] = y[5]

xfit = np.linspace(1,6,100)
yfit = np.polyval(p,xfit)

plt.scatter(x,y,label="data points")
plt.plot(xfit,yfit,label="fit")
plt.xlabel("x")
plt.ylabel("y")
plt.legend()
plt.show()

output plot:
- 中Q主 19 35 fit data points 30 25 20 15 10 5 3 4 5 N х

Add a comment
Know the answer?
Add Answer to:
please make sure the answer is correct %100 P1 This project requires you to solve the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please make sure the answer is correct 100% and to solve all parts clearly Tiara Company...

    Please make sure the answer is correct 100% and to solve all parts clearly Tiara Company has the following historical collection pattern for its credit sales: 70% collected in month of sale 15% collected in the first month after sale 10% collected in the second month after sale 4% collected in the third month after sale 1% uncollectible Budgeted credit sales for the last six months of the year follow. $ June 64,000 July 60,000 August 70,000 September 80,000 October...

  • C++ please Project: Working with Text Write an object-oriented program the performs the following tasks: ....

    C++ please Project: Working with Text Write an object-oriented program the performs the following tasks: . Reads a text file provided along with this data and maintains it an object. Determines the number of characters and keeps in the object. Determines the number of words and retains the result in the object. Determines the number of paragraphs and keeps the result in the object. A possible class definition: class Textutil { string text = ** int words = @; int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT