Question

HW8_4 Fit the data in the table using linear regression. Plot the data points as well as the regression line. Determine the vPlease write the codes in MATLAB.

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

%we are supposed to answer 1 question at a time

%HW8_4

clear
clc
close all
x=1:10;
y=[26.7 20.2 16.8 15.3 15.1 9.3 5.1 2.8 -1.1 -8.4];
%y=mx+c
p1=polyfit(x,y,1);
plot(x,y,'*',x,p1(1)*x+p1(2))
xlabel('x')
ylabel('y')
title(sprintf(' y = (%f) x + (%f)',p1))
legend('Data points','Linear fit')
sse=sum((y-polyval(p1,x)).^2);
ssto=sum((y-mean(y)).^2);
r21=1-sse/ssto;
fprintf(' y = (%f) x + (%f)\n',p1)
fprintf(' R squared value: %f\n',r21)
fprintf(' value of y when x = 7.2: %f\n',p1(1)*7.2+p1(2))
%x = ym + c

p2=polyfit(y,x,1);
figure
plot(y,x,'*',y,p2(1)*(y)+p2(2))
ylabel('x')
xlabel('y')
title(sprintf(' x = (%f) y + (%f)',p2))
legend('Data points','Linear fit')
sse=sum((x-polyval(p2,y)).^2);
ssto=sum((x-mean(x)).^2);
r22=1-sse/ssto;
fprintf(' x = (%f) y + (%f)\n',p2)
fprintf(' R squared value: %f\n',r22)
fprintf(' value of x when y = 15: %f\n',p2(1)*15+p2(2))

Command Window y-3.463030) x+(29.226667) R squared value: 0.968985 value of y when x = 7.2: 4.292848 x= (-0.279808) y + (8.34

Add a comment
Know the answer?
Add Answer to:
HW8_4 Fit the data in the table using linear regression. Plot the data points as well as the regr...
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