【问题标题】:Fit simulation to data with multiple fitting parameters将模拟拟合到具有多个拟合参数的数据
【发布时间】:2016-03-29 08:55:46
【问题描述】:

我有一组实验点

Xdata=[xd1 xd2...]

Ydata=[yd1 yd2...]

还有一个间接模拟的function y=myfunction(xsimul,a,b,c)

Ysimul=[ys1 ys2...]

Xsimul=Xdata

间接我的意思是没有直接计算 y=Function(x,a,b,c)。它是在两个 for 循环中通过最小化另一个函数 g=f(z)(使用 fminsearch)后跟 Ysimul=(g(targetvalue)) 来获得的。

目标是将模拟拟合到实验数据,并通过最小二乘法检索最佳 a、b 和 c 值。 我可以对参数给出一个很好的初步猜测。然而,拥有 3 个拟合参数,以及确定 Ysimul 的计算时间已经很长,使得这个问题变得相当麻烦。 所以我想知道的是:

使用 lsqcurvefit 之类的函数可以解决这个问题吗? 如果是这样,您能否提供有关如何操作的提示?

【问题讨论】:

  • 在这里确认:'Xdata' 和 'Ydata' 是大小相等的向量? 'a'、'b' 和 'c' 是标量吗?目标是找到“a”、“b”和“c”的最佳估计值以拟合所提供的数据?
  • 是的,Xdata 和 Ydata 大小相等,a,b,c 是要估计的标量。我应该指出这一点。并感谢您的快速回复!我会根据你的提示尝试实现算法

标签: matlab


【解决方案1】:

只是解决方案

这是lsqnonlin 的一个非常标准的用法,您只需要正确格式化它。意思是这样的:

%First, define a function whose inputs are a single vector, and whose
%outputs can be minimized
funToMinimize = @(abc) myfunction(Xdata,abc(1), abc(2), abc(3)) - Ydata;

%Define an initial guess of the values (including the size of the vector)
abcInitial = [0 0 0]; %Or whatever your best guess is

%Then use the nonlinear fit
abcFit = lsqnonlin(funToMinimize , abcInitial);

演示

我显然无法为您的myfunction 问题生成解决方案,但我们仍然可以完成重要步骤。

首先,让我们定义一个函数来模拟您的myfunctionXdataYdata

%Define some complicated-ish "myfuction", with inputs that match yours
myfunction = @(xsimul, a, b, c) sqrt(abs(xsimul))*a + sin(xsimul)*b*a^2 + c;
%Define "Xdata"
Xdata = linspace(0,10,100);
%Define "Ydata", note that I'm sneaking in a set of (a, b, c) values here
Ydata = myfunction(Xdata, 1, 2, 3);

现在,让我们运行上面答案中的步骤:

funToMinimize = @(abc) myfunction(Xdata,abc(1), abc(2), abc(3)) - Ydata;
abcInitial = [0 0 0];
abcFit = lsqnonlin(funToMinimize , abcInitial)

最后一步应该返回[1 2 3],匹配用于生成Ydata的(a, b, c)值。

【讨论】:

    猜你喜欢
    • 2018-12-09
    • 1970-01-01
    • 2010-09-27
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多