各位,我现在有如下一个二元函数,其中x,y是变量,a,b,c是常量。我得到了一系列的x,y的值,希望通过拟合求解a,b,c的值。
目前,尝试通过lsqcurvefit和nlinfit来做非线性拟合,初值是(0,0,3),下面是我的代码。
clear;
clc;
x=[4.044459,4.25085,5.113476,5.834796,3.814325,3.47099,4.676102,4.044458661,4.250850357,5.113475886,5.834795814,3.814324969]';
y=[4.492055,4.250656,3.71551,3.506852,4.882095,6.011205,3.923782,4.492054568,4.250655996,3.715510028,3.506851854,4.882095009]';
X=[x y];
n=length(y);
Y=ones(n,1);
func=@(a,X)((1./(1./(X(:,1)-a(1)).^2+1./(X(:,2)-a(2)).^2)).^0.5-a(3));
beta0=[0 0 3];
for l=1:5
    beta=lsqcurvefit(func,beta0,X,Y)
    beta=nlinfit(X,Y,func,beta0)
end
按照我的代码拟合出来的常量是a=0.0011,b=0.0010,c=2.0050,然后把常量代入到式子里的时候结果是对不上的,而且我目前知道c的值大概是3左右。尝试用1stopt,不过只有试用版,由于参数限制,所以把a、b的数值直接代入1stopt,得出来c是3.005。
matlab用的很少,所以也不知道式子是否能这么写,能麻烦各位帮忙看看matlab代码哪里写错了?或者有什么更好的方法能求出常量吗?谢谢大家了!

 Accepted Answer

0 votes

公式变换的对吗?想成y=f(x)的形式:
1:y=b+(1/(1/c^2-1/(x-a)^2))^0.5;
或:
2:y=b-(1/(1/c^2-1/(x-a)^2))^0.5;
两个都用1stOpt计算下,公式1结果如下(公式2似乎不合适)
Root of Mean Square Error (RMSE): 0.000101179748693782
Sum of Squared Residual: 1.22848098548842E-7
Correlation Coef. (R): 0.999999989350128
R-Square: 0.999999978700256
Adjusted R-Square: 0.99999997396698
Determination Coef. (DC): 0.999999978699661
Chi-Square: 1.56298476868793E-8
F-Statistic: 211264566.848354
Parameter Best Estimate
---------- -------------
a 0.0023493517977183
b 0.00230856656680433
c 3.00405441911676

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!