好吧,如果我遇到您的问题,您有一组数据,用于变量 x1 和 x2 以及 thre 结果 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));
现在让我们生成数据集
>> % 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)
代表我们猜测的值
像这样分离 de con(A - B) 也很有用:

还要记住
