【问题标题】:Wolfram Mathematica - Minimization of an absolute error with respect to two parametersWolfram Mathematica - 关于两个参数的绝对误差的最小化
【发布时间】:2018-03-24 03:30:33
【问题描述】:

我想最小化两个非线性 ODE 数值解之间的绝对误差。这是我使用的代码:

\[Epsilon] = 10^-6;
Delta[t_] := 1/(Sqrt[\[Pi]] \[Epsilon]) Exp[-(t/\[Epsilon])^2]
f[t_] := 1/2 (1 + Tanh[100 t])

solw = NDSolve[{w''[t] + (w[t] + w[t]^2) w'[t] == f[t], w[0] == 0, 
    w'[0] == 0}, w, {t, 0, 2 \[Pi]}, Method -> "MethodOfLines"];
wsol[t_] := Evaluate[w[t] /. solw]

solG = ParametricNDSolve[{G''[t] + (G[t] + G[t]^2) G'[t] == 
     s2 Delta[t], G[0] == 0, G'[0] == 0}, G, {t, 0, 2 \[Pi]}, {s2}, 
   Method -> "MethodOfLines"];
GGreen[t_, s2_] := Evaluate[G[s2][t] /. solG]
Gsol[t_, s1_, s2_] := 
 s1 NIntegrate[GGreen[\[Tau], s2] f[t - \[Tau]], {\[Tau], 0, t}, 
   Method -> "LocalAdaptive"]

然后,我将绝对误差及时离散化:

Table[Abs[wsol[t] - Gsol[t, s1, s2]], {t, 0, 1, 0.1}]

并使用命令:

NMinimize[
 Max[Table[
   Abs[wsol[t] - Gsol[t, s1, s2]], {t, 0, 1, 0.1}]], s1, s2]

但是,这不起作用,因为 s2 未在 Gsol 的 NIntegrate 中指定。

有没有办法最小化

Table[Abs[wsol[t] - Gsol[t, s1, s2]], {t, 0, 1, 0.1}]]

关于s1s2 同时?

为简单起见,s2 可以限制为[-2,2]

【问题讨论】:

  • 你应该在mathematica.stackexchange.com上发布这个

标签: wolfram-mathematica differential-equations minimize


【解决方案1】:

这是一个答案。

\[Epsilon] = 10^-6;
Delta[t_] := 1/(Sqrt[\[Pi]] \[Epsilon]) Exp[-(t/\[Epsilon])^2]
f[t_] := 1/2 (1 + Tanh[100 t])

solw = NDSolve[{w''[t] + Exp[w[t]] == f[t], w[0] == 0, w'[0] == 0}, 
   w, {t, 0, 2 \[Pi]}, Method -> "MethodOfLines"];
wsol[t_] := Evaluate[w[t] /. solw]

solG = ParametricNDSolve[{G''[t] + Exp[G[t]] == s2 Delta[t], 
    G[0] == 0, G'[0] == 0}, G, {t, 0, 2 \[Pi]}, {s2}, 
   Method -> "MethodOfLines"];
GGreen[t_, s2_] := Evaluate[G[s2][t] /. solG]
Gsol[t_, s1_, s2_] := 
 s1 NIntegrate[GGreen[\[Tau], s2] f[t - \[Tau]], {\[Tau], 0, t}, 
   Method -> "LocalAdaptive"]

interpol = 
  ListInterpolation[
   Table[Gsol[t, s1, s2], {t, 0, 1, 0.1}, {s2, -5, 5, 0.1}], {{0, 
     1}, {-5, 5}}];

NMinimize[{Max[
   Table[Abs[wsol[t] - interpol[t, s2]], {t, 0, 1, 0.1}]], -5 <= s2 <=
    5}, {s1, s2}]

但是,在 NMinimize 中选择s2 的范围时需要小心。对于-1 &lt;= 2 &lt;=2,该解决方案优于-3 &lt;= s2 &lt;=3。这意味着可能会有更好的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多