Question

6. You have a x-y relationship as follows 1 2 3 4 5 6 7 8 10 X 17.52 22.76 24.22 36.83 37.65 51.32 68.35 74.59 4.382 1.787 7.

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

Matlab Code:

x = 0:10;
y = [4.382 1.787 7.757 17.52 22.76 24.22 36.83 37.65 51.32 68.35 74.59];

%part a - selecting 4 points to solve for the coefficients
X = [x(1) x(4) x(8) x(11)]';
Y = [y(1) y(4) y(8) y(11)]';
A = [ones(4,1) X X.^2 X.^3];
coeffs1 = inv(A)*Y;
yb1 = coeffs1(1)+coeffs1(2).*x+coeffs1(3).*x.^2+coeffs1(4).*x.^3;
lsqerr1 = sum((y-yb1).^2);%least square error for part a
subplot(1,2,1);
plot(x,y); hold on
plot(x,yb1);
legend('y','yb1');

%part b
coeffs2 = polyfit(x,y,3);
yb2 = coeffs2(4)+coeffs2(3).*x+coeffs2(2).*x.^2+coeffs2(1).*x.^3;
lsqerr2 = sum((y-yb2).^2);%least square error for part b
subplot(1,2,2);
plot(x,y); hold on
plot(x,yb2);
legend('y','yb');

Command Window >> lsqerr2 lsqerr2 104.46 |» fx >>

80 80 y yb1 yb 70 60 60 50 50 40 20 20 10 10 0 10 5 C 5 10 LC 70 40 30 LO 30

Add a comment
Know the answer?
Add Answer to:
use matlab 6. You have a x-y relationship as follows 1 2 3 4 5 6 7 8 10 X 17.52 22.76 24.22 36.83 37.65 51.32 68.3...
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