Question

in MATLAB Curve fitting Given the following data, find the best linear functional relationship and cubic...

in MATLAB

Curve fitting

Given the following data, find the best linear functional relationship and cubic functional relationship using “polyfit,” “polyval,” and “plot” built-in functions. Plot all three fits that you got from Matlab. A rough plot by hand is allowable. You do not need to provide any codes.

     x = [-3, -2, 0, 1, 3, 4, 6, 7, 8, 9];

     y = [5, 7, 8, 10, 6, 2, -4, -6, -2, 1];

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

Code:

clc
clear

x = [-3, -2, 0, 1, 3, 4, 6, 7, 8, 9];
y = [5, 7, 8, 10, 6, 2, -4, -6, -2, 1];

pl = polyfit(x, y, 1);
yl = polyval(pl,x);

pc = polyfit(x, y, 3);
yc = polyval(pc,x);

plot(x, y, 'ro');
hold on
plot(x, yl, 'b-');
plot(x, yc, 'k--')
legend('data', 'linear fit', 'cubic fit')

Output:

o data linear fit ---.cubic fit -2 0 2 4 6 8 10

Add a comment
Know the answer?
Add Answer to:
in MATLAB Curve fitting Given the following data, find the best linear functional relationship and cubic...
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