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

2025-01-08 06:37:54
推荐回答(2个)
回答1:

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

程序:

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         

回答2:

用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

>>