How to determine the polynomial that provides the best fit to this data and use it to predict the thermal efficiency?

 Réponse acceptée

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 commentaires

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.
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)
THANKS TO Image Analyst :)
May Allah bless you with success, health, happiness, patience and strength..

Connectez-vous pour commenter.

Plus de réponses (1)

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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by