用Matlab进行曲线拟合失败了
我正在尝试在命令行中使用 fit
在 Matlab 中拟合曲线。输入数据是:
X =
1
2
4
5
8
9
10
13
Y =
1.0e-04 *
0.1994
0.0733
0.0255
0.0169
0.0077
0.0051
0.0042
0.0027
目标函数是
Y = 1/(kappa*X.^a)
我正在使用 fittype
、fitoptions
和 fit
如下:
model1 = fittype('1/(kappa*x.^pow)');
opt1 = fitoptions(model1);
opt1.StartPoint = [1e-5 -2];
[fit1,gof1] = fit(X,Y.^-1,model1,opt1)
我使用 得到结果rsquare
约为 -450,与测量方向大致相同。
编辑:
我删除了 fit 命令中的 .^-1
。这改善了行为,但并不完全正确。如果我将 model1 设置为:
model1 = fittype('1/(kappa*x.^pow)');
拟合不好。如果我将其设置为:
model1 = fittype('kappa*x.^pow');
拟合良好(kappa 是一个非常小的数字,pow 为负数)。
我还标准化了 Y
并且得到了合理的结果
I'm trying to fit a curve in Matlab using fit
in command line. The input data is:
X =
1
2
4
5
8
9
10
13
Y =
1.0e-04 *
0.1994
0.0733
0.0255
0.0169
0.0077
0.0051
0.0042
0.0027
And the target function is
Y = 1/(kappa*X.^a)
I am using fittype
, fitoptions
, and fit
as follow:
model1 = fittype('1/(kappa*x.^pow)');
opt1 = fitoptions(model1);
opt1.StartPoint = [1e-5 -2];
[fit1,gof1] = fit(X,Y.^-1,model1,opt1)
I get results with rsquare
of roughly -450 which are vaguely in the same direction as the measurement.. How can I improve Matlab fitting skills?
Edit:
I removed the .^-1
in the fit command. This improved the behavior but it is not entirely correct. If I set model1 to be:
model1 = fittype('1/(kappa*x.^pow)');
The fit is bad. If I set it to be:
model1 = fittype('kappa*x.^pow');
The fit is good (with kappa being a very small number and pow being negative).
I have also normalized Y
and I get a reasonable results
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该替换
为
另外,
kappa
的初始条件是1e-5
,如果kappa
位于分子中,则这才有意义。使用模型
kappa*x.^pow
,初始条件为[1e-5 -2]
,您将得到正确的拟合:拟合结果为
You should replace
by
Also your initial condition for
kappa
is1e-5
, which would make sense ifkappa
was in the numerator.Using the model
kappa*x.^pow
, with the initial condition[1e-5 -2]
, you would get the right fit:The fitted result is