Mathematica:FindFit for NIntegrate of ParametricNDSolve

时间:2017-08-24 22:17:59

标签: wolfram-mathematica curve-fitting

我已经看到了几个非常类似主题的答案,使用了?NumericQ解释了,但仍然无法理解我的实现有什么问题,我的示例可以按照我想要的方式进行评估。 我有ParametricNDSolve形式的微分方程的解(我相信方程的确切形式是无关紧要的):

sol = ParametricNDSolve[{n'[t] == g/(1/(y - f*y) + b*t + g*t)^2 - a*n[t] - c*n[t]^2, n[0] == y*f}, {n}, {t, 0, 10}, {a, b, c, g, f, y}]

之后我试图为FindFit或类似的程序构建一个函数,Nintegrating over function n [a,b,c,g,f,y,t]我已经得到了一些乘数(我选择了Log [ z]作为简单的乘数)

Func[z_, a_, b_, c_, g_, f_] := 
 NIntegrate[
  Log[z]*(n[a, b, c, g, f, y][t] /. sol), {t, 0, 10}, {y, 0, Log[z]}]

所以我对从ParametricNDSolve派生的函数n [params,t]进行了NIntegrate,乘法器引入了新的变量(z),它也存在于积分的极限中(为了简单起见,与乘法器的形式相同)

我可以使用给定的参数值(a,b,c,g,f)在任意点(z)评估函数Func的值:Func(0,1,2,3,4,5) )可以评估。 但由于某些原因,我不能像这样使用FindFit:

FindFit[data, Func[z, a, b, c, g, f], {a, b, c, g, f}, z]

错误是:NIntegrate :: nlim:y = Log [z]不是有效的集成限制。

我尝试过很多不同的组合?NumericQ的用法似乎无处可去。任何帮助,将不胜感激! 在此问题解释中,提前致谢并抱歉纯英语。

1 个答案:

答案 0 :(得分:0)

以下是定义函数的方法:

sol = n /. 
  ParametricNDSolve[{n'[t] == 
     g/(1/(y - f*y) + b*t + g*t)^2 - a*n[t] - c*n[t]^2, 
    n[0] == y*f}, {n}, {t, 0, 10}, {a, b, c, g, f, y}]

Func[z_?NumericQ, a_?NumericQ, b_?NumericQ, c_?NumericQ, g_?NumericQ, 
  f_?NumericQ] := 
    NIntegrate[Log[z]*sol[a, b, c, g, f, y][t],
      {t, 0, 10}, {y, 0, Log[z]}]

测试:Func[2, .45, .5, .13, .12, .2] - > 0.106107

我并不乐观,你会从FindFit得到一个具有如此多参数的函数并且计算成本太高的好结果。