用lsqcurvefit拟合曲线

时间:2013-04-08 10:41:39

标签: matlab curve-fitting nonlinear-optimization

我将某个功率谱数组保存为test,具体取决于频率数组f

此功率谱通常如下图所示 enter image description here

值得注意的是,上述功率谱源于模拟时间序列。

原则上我想做的是拟合接近模拟功率谱的曲线,如下所示:

enter image description here

我知道理论功率谱可以定义如下:

function ps_theo = ps_th(L,Uhub,f)

const = L/Uhub;
f_x = 6.*f.*(L/Uhub);
exp = 5/3;
ps_theo = (4*const)./((1 + f_x).^exp);

end

其中L是一个恒定长度比例,Uhub,一个恒定的速度和f频率向量。

问题是:我不知道'L'的值,因此我使用lsqcurvefit来考虑优化的非线性分辨率

我一直在进行如下操作:

xdata = f;
ydata = test;
Uhub = 10;

fit_func = @(L) ps_th(L,Uhub,f);

L_opt = lsqcurvefit(@fit_func,330.2,xdata,ydata)

检索fit_func函数的输入变量数的错误消息。

你想介绍一下吗?

1 个答案:

答案 0 :(得分:1)

您拟合的功能只能包含两个参数。您可以像这样重写ps_th

function ps_theo = ps_th(x0,f)
L = x0(1);
Uhub = x0(2);

const = L/Uhub;
f_x = 6.*f.*(L/Uhub);
exp = 5/3;
ps_theo = (4*const)./((1 + f_x).^exp);

end

然后用这样的方式调用lsqcurvefit:

x0Start = [330.2,10]; % vector of initial parameters
x0_opt = lsqcurvefit(@ps_th,x0Start,xdata,ydata);
相关问题