How can I extrapolate point outside of given data

1 view (last 30 days)
I've been given data points for power consumption as a function of speed that goes up to 200 km/h, I now want to estimate the energy consumption for speeds up to 220 km/h. I'm meant to use polyfit to fit polynomials of degree 2, 4, 8 and 12 to the data points, which i know how to do but I don't understand how to plot all the fits, with speeds between 0 and 220 km/h (as i've only been given data up to 200). I'm meant to do this to understand which polynomial degree is most suitable to use. Could anyone help with this?
This is my code so far:
%plot power consumption as a function of speed, start by giving x and y.
x=speed_kmph;
y=consumption_Whpkm;
plot(x,y, 'o')
hold on
%b)
%Fit a degree-two polynomial, use first,last and 600 points to create a
%dense x-axis
p=polyfit(x,y,2);
yy=linspace(x(1),x(end),600);
%evaluate p, now stored in yy.
fyy=polyval(p,yy);
%plot curve
plot(yy,fyy)
%c)
%Fit 2,4,8 and 12 degree polynomial
pp=polyfit(x,y,4);
fyx=polyval(pp,yy);
ppp=polyfit(x,y,8);
fxx=polyval(ppp,yy);
pppp=polyfit(x,y,12);
fyyy=polyval(pppp,yy);

Accepted Answer

Matt J
Matt J on 11 Nov 2021
Instead of using x(1) and x(end) in
yy=linspace(x(1),x(end),600);
use whatever range limits you plan to plot over.

More Answers (0)

Categories

Find more on Polynomials in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!