已知函数关系式,用matlab进行数据拟合?
所谓拟合精度无非是循环的时候退出的条件,而你的问题可以转化成:
clc; clear
% 比如 x->xy(:,1); y->xy(:,2)
xy = [
1, 1.015608713353;
2, 20.462100415518;
3, 94.4267300097118;
4, 130.896501799540;
5, 169.7239268832727;
6, 310.773635794259;
7, 680.660210398064;
8, 1202.16423450355;
9, 1529.61068657942;
10, 1539.78928190371
];
abc = 1*rand(3,1); % a->abc(1); b->abc(2); c->abc(3)
myfun = @(abc,xy) log(xy(:,2)-abc(1)) - abc(2)*log(xy(:,1))-abc(3);
opt.TolX = 1e-1;
abc = nlinfit(xy, zeros(size(xy,1),1), myfun, abc);
plot(xy(:,1),xy(:,2),'r*')
hold on
% x = 1:0.1:10;
ezplot(@(x,y)myfun(abc,[x,y]),[1 10 0 2000])
title('曲线拟合');legend('样本点','拟合曲线')