Mostrar comentarios más antiguos
各位,我现在有如下一个二元函数,其中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代码哪里写错了?或者有什么更好的方法能求出常量吗?谢谢大家了!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre 线性最小二乘 en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!