Question

Consider the following data: x : -7, -5, -1, 0, 2, 5, 6, .y: 15, 12...

Consider the following data: x : -7, -5, -1, 0, 2, 5, 6, .y: 15, 12 ,5, 2, 0, -5, -9. Using linear regression find the equation in the form y=mx+b.  b) Check your results for the coefficients in the trial function using a built-in function in Matlab, Python, or Mathematica. c) Plot the data points as dots and the best-fit line as a solid line on the same figure.

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

MatLab program

clear all
clc
close all
% given data
x=[-7 -5 -1 0 2 5 6];
y=[15 12 5 2 0 -5 -9];
% fitting
p=polyfit(x,y,1);
m=p(1);
c=p(2);
% fitted data
x1=x;
y1=m*x1+c;
plot(x,y,'o',x1,y1)
xlabel('x');
ylabel('y');
legend('given data','plotted data')
fprintf('best fit line is %.4fx+%.4f',m,c);

Screenshot

Save the above program and execute it.

Result

I hope this will help you.

Add a comment
Know the answer?
Add Answer to:
Consider the following data: x : -7, -5, -1, 0, 2, 5, 6, .y: 15, 12...
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