[英]Multiple Variable Non Linear Regression OR Curve Fitting Matlab
我有一组嘈杂的数据,虽然我想在MATLAB中拟合一个自定义方程。 接下来,我将获取系数的值并将其用于我的算法中。 但是我被困住了,我不知道为什么。 我使用一个非线性方程a + b * log10(x1-dcos(alpha-x2)),其中x1,x2和响应值是已知的。 第一个问题是a,b和alpha的系数必须有界。 例如,这里的Alpha角度只能在0到360之间变化。我不知道如何使用曲线拟合工具箱来实现。
我还尝试了其他选项,例如MATLAB中的非线性回归技术(fitnlm,lsqcurvefit等),由于我对这些变量没有界限,这被证明是令人失望的。 因此,尽管拟合度非常好,但系数仍然太差。
因此,问题1:如何使用曲线拟合来拟合多个变量? 问题2:如果那不可能,那么除了非线性回归之外,我还可以使用其他哪些技术。
提前很多准备! 祝你有美好的一天 !
好吧,如果我遇到您的问题,您有一组数据,对于变量x1和x2以及结果y,您希望使用以下等式对其进行建模:
y = a + b * log10(x1 - cosd(alpha - x2)) % I suppose that dcos = cosd, I do not really known this functions
首先,我将为此值创建数据:
function y = getting_data(x1,x2)
a = 3;
b = 5;
alpha = 120;
y = a + b * log10(x1 - cosd(alpha - x2));
现在让我们生成de数据集
>> % generate the data sets
>> x1 = 9 .* rand(1000,1) + 1; % random values [1,10]
>> x2 = 360 .* rand(1000,1); % random values [0,360]
>> y = getting_data(x1,x2); % the values for the function
创建一个使用曲线拟合模型的函数
function myfit = fitting_data(x1,x2,y)
myfittype = fittype('a + b * log10(x1 - cosd(alpha - x2))',...
'dependent',{'y'},'independent',{'x1','x2'},...
'coefficients',{'a','b','alpha'})
myfit = fit([x1 x2],y,myfittype)
注意输入向量,它应该是拟合函数的nx1
最后我们得到系数:
>> fitting_data(x1,x2,y)
myfittype =
General model:
myfittype(a,b,alpha,x1,x2) = a + b * log10(x1 - cosd(alpha - x2))
Warning: Start point not provided, choosing random start point.
> In curvefit.attention.Warning/throw (line 30)
In fit>iFit (line 299)
In fit (line 108)
In fitting_data (line 7)
General model:
myfit(x1,x2) = a + b * log10(x1 - cosd(alpha - x2))
Coefficients (with 95% confidence bounds):
a = 3 (3, 3)
b = 5 (5, 5)
alpha = 120 (120, 120)
General model:
ans(x1,x2) = a + b * log10(x1 - cosd(alpha - x2))
Coefficients (with 95% confidence bounds):
a = 3 (3, 3)
b = 5 (5, 5)
alpha = 120 (120, 120)
代表我们猜测的价值
像这样分隔con(A-B)也会很有用:
还要记住
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.