How to determine the polynomial that provides the best fit to this data and use it to predict the thermal efficiency?
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
Accepted Answer
Image Analyst
on 20 May 2013
The best fit will be a 9th order polynomial - it will go through each point exactly. However it will be badly behaved because in between the points it will go haywire so the estimates will be worthless. So, like Wayne said, you need to decide on an order. As the orders get higher, the fit will get better, but the worse the oscillations in between your training points will be. Once you know that, just do
coefficients = polyfit(x, y, theOrder); % x is the year.
x = 2000;
estimatedY = polyval(coefficients, x);
11 Comments
could you write the code for me? is difficult to write the right code, I see a lot of orange marks under the code :(
No, because it's your homework assignment. Anyway, it's all practically written already. All you have do is assign the years to the x array, and the efficiency to the y array, and call my code. Two more lines and you're done. I can't give you those two lines without doing 100% of the assignment for you. You can post your code if you need help with orange or red lines.
Djati Waluyo
on 20 May 2013
Edited: Djati Waluyo
on 20 May 2013
Thanks, I would be proud if I had a lecturer like you :)
coefficients = polyfit(x, y, theOrder); % x is the year. what is "theOrder" means?
the Order means the maximum power of the coefficients, the degree of the polynomial
Try an integer between 2 and 9 and see how it goes. See which number looks like a fairly smooth regression and how looks by plotting it like this:
plot(x,y, 'bo', 'LineWidth', 2, 'MarkerSize', 8);
[coefficients, S, mu] = polyfit(x, y, theOrder); % x is the year.
x = 1700:2050;
estimatedY = polyval(coefficients, x, S, mu);
hold on;
plot(x, estimatedY, 'r-', 'LineWidth', 2);
grid on;
yl = ylim;
line([2000 2000], [yl(1), yl(2)], 'Color', 'r', 'LineWidth', 4);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
indexAt2000 = find(x==2000)
efficiencyAt2000 = estimatedY(indexAt2000)
is this true?
x = [1718, 1767, 1774, 1775, 1792, 1816, 1828, 1834, 1878, 1906];
y = [0.5, 0.8, 1.4, 2.7, 4.5, 7.5, 12.0, 17.0, 17.2, 23.0];
format short e
while 1
k = input('degree of polynomial = ');
if isempty(k) % Loop is terminated
fprintf('Done') % by pressing ’’return’’
break
end
a = polyfit(x, y, k+1); % x is the year.
x = 2000;
estimatedY = polyval(a, x);
plot(x,y,'o',x,estimatedY,'-')
axis([1718 2000 0 30])
The x any y are correct. I suggest you use my code for polyfit(), polyval(), and plotting.
Like this?
x = [1718, 1767, 1774, 1775, 1792, 1816, 1828, 1834, 1878, 1906];
y = [0.5, 0.8, 1.4, 2.7, 4.5, 7.5, 12.0, 17.0, 17.2, 23.0];
plot(x,y, 'bo', 'LineWidth', 2, 'MarkerSize', 8);
[coefficients, S, mu] = polyfit(x, y, theOrder); % x is the year.
x = 1700:2050;
estimatedY = polyval(coefficients, x, S, mu);
hold on;
plot(x, estimatedY, 'r-', 'LineWidth', 2);
grid on;
yl = ylim;
line([2000 2000], [yl(1), yl(2)], 'Color', 'r', 'LineWidth', 4);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
indexAt2000 = find(x==2000)
efficiencyAt2000 = estimatedY(indexAt2000)
Djati Waluyo
on 20 May 2013
Edited: Djati Waluyo
on 20 May 2013

THANKS TO Image Analyst :)
May Allah bless you with success, health, happiness, patience and strength..
More Answers (1)
Wayne King
on 20 May 2013
You have to know what order polynomial you want to fit. Then use polyfit().
Read the help for polyfit() to see how to use the function. Once you have the polynomial, you can just plug in the year 2000 and that will answer your question.
Categories
Find more on Array and Matrix Mathematics in Help Center and File Exchange
Tags
See Also
on 20 May 2013
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
