(MATLAB Coding) The total world oil production in millions of barrels per day is
ID: 3869963 • Letter: #
Question
(MATLAB Coding)
The total world oil production in millions of barrels per day is shown in the table that follows.
(a) Use the matlab intrinsic function polyfit to determine the degree 9 polynomial through the data and estimate 2010 oil production. Does the Runge phenomenon occur in this example?
(b) Use the function polyval to plot the data.
(c) In your opinion, is the interpolating polynomial a good model of the data? Explain. Hint: You will need to scale the x-coordinate of your fit by subtracting 2000 from each year before the interpolation. This will avoid the calculation, for example, of P9(2003) which will explode with numerical errors.
Show me the code in MATLAB, please.
year bbl/day (x10) 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 67.052 68.008 69.803 72.024 73.400 72.063 74.669 74.487 74.065 76.777Explanation / Answer
function [] = interpolation_adv ()
x=1994:2003;
x=x-2000;
y=[67.052,68.008,69.803,72.024,73.400,72.063,74.669,74.487,74.065,76.777];
n=9;
p=polyfit(x,y,n);
y1=polyval(p,10);%interpoolated value at 2010
disp('value at 2010 is');
disp(y1);
y2=polyval(p,x);
errors=[];
for i=1:100
p1=polyfit(x,y,i);
y3=polyval(p,x);
errors=[errors,max(y3-y)];
end
plot(x,y);%plot with original values
figure;
plot(x,y2);%plot with interpolated values
figure;
plot(1:100,errors);%here error value remains constant with increasing order of polynomial,instead g increasing hence
%runge phenmenon does not occur here
endfunction
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.