How to get polynomial equation of polyfit?
Show older comments
Hello. I have the following code and the data. I need to find the equation of the polynomial and write it on the graph. Also, I will be changing the x and y datas so, it needs to be specific for a set of datas. Thank you for your help! It will be appreciated!!
clc;
clear;
y = [4.0432,4.1073,4.0899,4.1319,4.2885,4.4305,4.5249,4.6172,4.6962,4.7235,4.5987,4.7927,4.895,4.9079];
x = [1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012];
pf = polyfit(x,y,2);%Calculating the corresponding polynomial function
disp('The coefficients of the desired polynomial:');
fprintf('%3.3f\n',pf) %Showing the coefficients of the fitted polynomial function
pv = polyval(pf,x);%Calculating the values of polynomial function at x's
disp('The values of polynomial at given set of x values:');
fprintf('\n %3.3f',pv)
scatter(x,y)
hold on
plot(x,pv)
hold off
Accepted Answer
More Answers (1)
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!
