有没有人会用matlab求曲线拟合方程和拟合曲线。。大神啊 高分求帮助!!

这是数据。。。。希望能用matlab最小二乘法求出拟合曲线和拟合方程。。。。。急求啊 要给出代码!!在线等!!!!
(利用常见的最小二乘原理拟合1996年—2008年生均学费与国家生均预算内教育经费的关系。。
最后的拟合方程应该是这样。。求代码!

下面程序同你的结果一样,另外还画了图

程序:

x=[1401 1728 2026 2765 2060 3724 4097 4309 4576 4772 4637 6103 6598];

y=[7222 7893 9287 9676 7209 7991 7597 6879 6577 6305 6530 7754 9048];

a=polyfit(x,y,3);

syms X

fy=vpa(poly2sym(a,X),4)%制定v为变量。函数默认x为自变量

 

x1=min(x):max(x);

h1=polyval(a,x1);

plot(x,y,'o',x1,h1)

xlabel('x');

ylabel('y')

title('多项式3次拟合曲线')

legend('原始数据点','3次拟合')


结果:

fy =

 

2.926e-7*X^3 - 0.003427*X^2 + 11.84*X - 3745.0         

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-07-11
用polyfit拟合

代码:
>> format long
x=[1401 1728 2026 2765 2060 3724 4097 4309 4576 4772 4637 6103 6598];
y=[7222 7893 9287 9676 7209 7991 7597 6879 6577 6305 6530 7754 9048];
polyfit(x,y,3)

结果:
Warning: Polynomial is badly conditioned. Add points with distinct X
values, reduce the degree of the polynomial, or try centering
and scaling as described in HELP POLYFIT.
> In polyfit at 76

ans =

1.0e+03 *

Columns 1 through 3

0.000000000292571 -0.000003426586636 0.011838259318403

Column 4

-3.744504955886163

>>追问

按照您这个运行出来答案和我给的那个一样吗?