Question

Using MATLAB,The following data is given: 13 14 15 15 2 10 12 (a) Use linear least-squares regression to determine the coefficients m and b in the function y - mx+b that best fits the data (b) Make a plot that shows the function and the data points.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the working commented code below :
---------------------------------------------------------------------------------------------------

x = [2,5,6,8,9,13,15]    %declare arrays x and y
y = [7,8,10,11,12,14,15]
scatter(x,y,25,'b','*')    %Plot points
P = polyfit(x,y,1);    %find the coefficients using polyfit function with 1 as parameter, to signify linear fit
yfit = P(1)*x+P(2);    %define the regression line
hold on;
plot(x,yfit,'r-.');    %plot the regression line

---------------------------------------------------------------------------------------------------

Please find the screenshot of the output below :

Command Window Figure 1 >x[2,5,6,8,9, 13, 15] Eile Edit View Insert Iools Desktop Window Help 5 6 9 13 15 16 15 14 13 12 [7,8,10,11,12,14, 15] 10 11 12 14 15 >scatter (x,y,25, b,*) yfitP(1)*x+P(2); plot(x,yfit,r) polyfit(x,y,1); >>hold on; 10 ans 0.6400 10 12 14 16 4 6 5.6968

Add a comment
Know the answer?
Add Answer to:
Using MATLAB, The following data is given: 13 14 15 15 2 10 12 (a) Use...
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
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