ParametricNDSolveValue[eqns,expr,{x,xmin,xmax},pars]
给出由常微分方程 eqns 的数值解决定的函数的 expr 值,其中自变量 x 位于从 xmin 到 xmax 的范围内,参数为 pars.
ParametricNDSolveValue[eqns,expr,{x,xmin,xmax},{y,ymin,ymax},pars]
在矩形区域上求解偏微分方程 eqns.
ParametricNDSolveValue[eqns,expr,{x,y}∈Ω,pars]
在区域 Ω 上求解偏微分方程 eqns.
ParametricNDSolveValue[eqns,expr,{t,tmin,tmax},{x,y}∈Ω,pars]
在区域 Ω 上求解时间相关偏微分方程 eqns.
ParametricNDSolveValue
ParametricNDSolveValue[eqns,expr,{x,xmin,xmax},pars]
给出由常微分方程 eqns 的数值解决定的函数的 expr 值,其中自变量 x 位于从 xmin 到 xmax 的范围内,参数为 pars.
ParametricNDSolveValue[eqns,expr,{x,xmin,xmax},{y,ymin,ymax},pars]
在矩形区域上求解偏微分方程 eqns.
ParametricNDSolveValue[eqns,expr,{x,y}∈Ω,pars]
在区域 Ω 上求解偏微分方程 eqns.
ParametricNDSolveValue[eqns,expr,{t,tmin,tmax},{x,y}∈Ω,pars]
在区域 Ω 上求解时间相关偏微分方程 eqns.
更多信息和选项
- ParametricNDSolveValue 给出具有 ParametricFunction 对象的结果.
- {pspec1,pspec2,…} 的参数 pars 的规范可用于指定范围.
- pspeci 的可能形式为:
-
p p 值为 Reals 或 Complexes Element[p,Reals] p 值为 Reals Element[p,Complexes] p 值为 Complexes Element[p,{v1,…}] p 具有离散值 {v1,…} {p,pmin,pmax} p 值为 
- 通常 expr 会通过微分方程组的解间接与参数相关,但是可能显式与参数相关.
- 由此得出关于参数的 ParametricFunction 对象的导数会尽可能地组合使用符号和数值灵敏度方法进行计算.
- ParametricNDSolveValue 接受与 NDSolve 同样的选项和设置.
- NDSolve 和 ParametricNDSolveValue 通常通过多个不同的阶段求解微分方程组. 当 Method->{s1->m1,s2->m2,…} 时,阶段 si 由方法 mi 处理. 基于所要解决的问题,实际使用的阶段和顺序是由 NDSolve 决定的.
- 可能的解阶段与 NDSolve 是一样的,但还包括:
-
"ParametricCaching" 缓存计算的解 "ParametricSensitivity" 关于参数导数的计算 -
AccuracyGoal Automatic 所寻求的绝对精度的位数 Compiled Automatic 表达式是否应该自动编译 DependentVariables Automatic 所有应变量的列表 EvaluationMonitor None 每当计算函数时需要计算的表达式 InitialSeeding {} 用于某些算法的播种方程 InterpolationOrder Automatic 最终输出的连续性度数 MaxStepFraction 1/10 每个步骤所覆盖求解范围的最大比例 MaxSteps Automatic 采用步骤的最大数目 MaxStepSize Automatic 每个步骤的最大步长 Method Automatic 使用的方法 NormFunction Automatic 误差估计使用的范数 PrecisionGoal Automatic 所寻求的精度的位数 StartingStepSize Automatic 初始步长 StepMonitor None 每进行一个步骤时,要计算的表达式 WorkingPrecision MachinePrecision 内部计算使用的精度
所有选项的列表
范例
打开所有单元 关闭所有单元基本范例 (3)
pfun = ParametricNDSolveValue[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}]y1 = pfun[1]y1[10]Plot[Evaluate[Table[pfun[a][t], {a, -1, 1, .1}]], {t, 0, 1}, PlotRange -> All]pfun = ParametricNDSolveValue[{f''[t] + a f[t] == 0, f[0] == 1, f'[0] == 0}, f[10], {t, 0, 10}, {a}]Plot[pfun[a], {a, 0, 2}]使用 FindRoot 函数求根:
FindRoot[pfun[a], {a, 1}]pfun = ParametricNDSolveValue[{f''[t] + a f[t] == 0, f[0] == b, f'[0] == 0}, f, {t, 0, 20}, {a, b}];Plot[Evaluate[(pfun[a, b][t] + {0, .1, -.1}D[pfun[a, b][t], a]) /. {a -> 1, b -> 1}], {t, 0, 20}, Filling -> {2 -> {3}}]Plot[Evaluate[(pfun[a, b][t] + {0, .1, -.1}D[pfun[a, b][t], b]) /. {a -> 1, b -> 1}], {t, 0, 20}, Filling -> {2 -> {3}}]范围 (6)
参数相关 (4)
ParametricNDSolveValue 返回一个 ParametricFunction 对象:
pfun = ParametricNDSolveValue[{y''[t] + y[t] == 3a Sin[y[t]], y[0] == y'[0] == 1}, y, {t, 0, 5}, {a}]if0 = pfun[0]Plot[if0[t], {t, 0, 5}]Plot[Evaluate@Table[pfun[a][t], {a, -.5, .5, .05}], {t, 0, 5}, PlotRange -> All]pfun = ParametricNDSolveValue[{y''[t] + 2y[t] == Sin[.4t] + Cos[y[t]], y[0] == a, y'[0] == b}, y, {t, 0, 10}, {a, b}]Plot[Evaluate@Table[pfun[a, 1][t], {a, -2, 2, .5}], {t, 0, 10}, PlotRange -> All]Plot[Evaluate@Table[pfun[1, b][t], {b, -2, 2, .5}], {t, 0, 10}, PlotRange -> All]eqns = {y''[t] + y[t] == 3a Sin[y[t]], y[0] == y'[0] == 1};pfun = ParametricNDSolveValue[eqns, y[1] + y[2], {t, 0, 5}, {a}];Plot[pfun[a], {a, -2, 2}]pfun = ParametricNDSolveValue[eqns, Underoverscript[∑, i = 1, 10]0.5 y[0.5 i], {t, 0, 5}, {a}];Plot[pfun[a], {a, -2, 2}]pfun = ParametricNDSolveValue[eqns, Subsuperscript[∫, 0, 5]y[s]ⅆs, {t, 0, 5}, {a}];Plot[pfun[a], {a, -2, 2}]pfun = ParametricNDSolveValue[eqns, y'[3], {t, 0, 5}, {a}];Plot[pfun[a], {a, -2, 2}]pfun = ParametricNDSolveValue[eqns, y[a], {t, 0, 5}, {a}];Plot[pfun[a], {a, 0, 5}]pfun = ParametricNDSolveValue[{u''[x] == a u[x], DirichletCondition[u[x] == 1, x == 0], DirichletCondition[u[x] == b, x == 1]}, u, {x}∈Line[{{0}, {1}}], {a, b}]Plot[Evaluate@Table[pfun[a, 1 / 2][t], {a, -2, 2, .5}], {t, 0, 10}, PlotRange -> All]参数灵敏度 (2)
pfun = ParametricNDSolveValue[{y''[t] + y[t] == 0, y[0] == a, y'[0] == 0}, y, {t, 0, 10}, {a}];Show[Plot[Evaluate@Table[pfun[a][t], {a, 1, 3, .2}], {t, 0, 10}, PlotStyle -> Thin], Plot[pfun[2][t], {t, 0, 10}]]Plot[pfun'[2][t], {t, 0, 10}]Plot[Evaluate[pfun[2][t] + {-1, 0, 1}pfun'[2][t]], {t, 0, 10}, PlotStyle -> {Gray, {Blue}, Gray}, Filling -> {1 -> {3}}]pfun = ParametricNDSolveValue[{y''[t] + 2y[t] == Sin[t] + Cos[y[t]], y[0] == a, y'[0] == b}, y, {t, 0, 10}, {a, b}];ifun = pfun[1, 1]ifuna = D[pfun[a, 1], a] /. a -> 1;Plot[Evaluate[ifun[t] + {-.5, 0, .5}ifuna[t]], {t, 0, 10}, PlotStyle -> {Gray, {Blue}, Gray}, Filling -> {1 -> {3}}]ifunb = D[pfun[1, b], b] /. b -> 1;Plot[Evaluate[ifun[t] + {-.5, 0, .5}ifunb[t]], {t, 0, 10}, PlotStyle -> {Gray, {Blue}, Gray}, Filling -> {1 -> {3}}]推广和延伸 (2)
求各种 WorkingPrecision 值的
且
的解,并绘制误差:
err = ParametricNDSolveValue[{x'[t] == x[t], x[0] == 1}, Abs[x[1] - E], {t, 0, 1}, {wp}, Method -> "Extrapolation", WorkingPrecision -> wp ];ListLogPlot[Table[{wp, err[wp]}, {wp, 16, 60}]]考虑求出 NDSolveValue 无法直接求解的高度非线性问题的解. 设置边界条件、区域和依赖于参数
的方程:
eqn[p_] := Inactive[Div][((x ^ 2 + 3) * D[u[x], x] ^ (p - 1)) Inactive[Grad][u[x], {x}], {x}] - Sin[x]
bc = DirichletCondition[u[x] == 0, True];
Ω = Line[{{0}, {1}}];NDSolveValue 无法求解:
NDSolveValue[{eqn[3] == 0, bc}, u, Element[{x}, Ω]]Clear[seeding]
seeding[x_ ? NumericQ] := 0基于参数
创建 ParametricNDSolveValue 函数:
psol = ParametricNDSolveValue[{eqn[p] == 0, bc}, u, Element[{x}, Ω], {p}, InitialSeeding -> {u[x] == seeding[x]}]s1 = psol[1]Clear[seeding]
seeding[x_ ? NumericQ] := s1[x]s2 = psol[3]Plot[s2[x], {x, 0, 1}]选项 (2)
Method (2)
ParametricCaching (1)
pfun = ParametricNDSolveValue[{x''[t] + a x[t] == 0, x[0] == b, x'[0] == 0}, x, {t, 0, 1000}, {a, b}, MaxSteps -> ∞, Method -> {"ParametricCaching" -> None}];Do[Print[Module[{m = MemoryInUse[]}, AbsoluteTiming[{ByteCount[pfun[2, 2]], MemoryInUse[] - m}]]], {3}]pfun = ParametricNDSolveValue[{x''[t] + a x[t] == 0, x[0] == b, x'[0] == 0}, x, {t, 0, 1000}, {a, b}, MaxSteps -> ∞];Do[Print[Module[{m = MemoryInUse[]}, AbsoluteTiming[{ByteCount[pfun[2, 2]], MemoryInUse[] - m}]]], {3}]ParametricSensitivity (1)
pfun = ParametricNDSolveValue[{x'[t] == a x[t], x[0] == b}, x[1], {t, 0, 1}, {a, b}, Method -> {"ParametricSensitivity" -> None}];Plot3D[pfun[a, b], {a, 1, 2}, {b, 0, 1}]dfun = Derivative[1, 0][pfun];
dfun[1, 1]应用 (15)
参数扫描 (8)
pfun = ParametricNDSolveValue[{y''[t] == -9.8bounce[t], y[0] == height, y'[0] == 0, bounce[0] == 1, WhenEvent[y[t] == 0, If[Abs[y'[t]] > 10 ^ -6, y'[t] -> -0.7 y'[t], {bounce[t], y'[t]} -> {0, 0}]]}, y[t], {t, 0, 4}, {height}, DiscreteVariables -> bounce];Plot[Evaluate[Table[pfun[height], {height, 1, 5, .2}]], {t, 0, 4}, PlotRange -> All]pfun = ParametricNDSolveValue[{x''[t] - x'[t] + x[t] == 0, x[0] == 1, x'[0] == s}, x[10], {t, 0, 10}, {s}];root = FindRoot[pfun[s] == 0, {s, 6}]NDSolve[{x''[t] - x'[t] + x[t] == 0, x[0] == 1, x'[0] == s} /. root, x, {t, 0, 10}];Plot[x[t] /. %, {t, 0, 10}]psol = ParametricNDSolveValue[{x''[t] - x'[t] + x[t] == 0, x[0] == 1, x'[0] == s}, x, {t, 0, 10}, {s}];Show[Plot[Evaluate@Table[Tooltip[psol[s][t], s], {s, 1, 1.8, 0.1}], {t, 0, 10}, PlotStyle -> Lighter[Gray, 0.5]],
Plot[psol[s][t] /. root, {t, 0, 10}, PlotStyle -> Orange]]求边界值问题
,
,
的多个解. 首先考虑
的多个可能的值:
psol = ParametricNDSolveValue[{y''[t] + Sin[y[t]] == 0, y[0] == 0, y'[0] == s}, y, {t, 0, 10}, {s}];Plot[Evaluate@Table[Tooltip[psol[s][t], s], {s, 0.3, 1.9, 0.1}], {t, 0, 10}]pfun = ParametricNDSolveValue[{y''[t] + Sin[y[t]] == 0, y[0] == 0, y'[0] == s}, y[10], {t, 0, 10}, {s}];Plot[pfun[s], {s, 0, 2.1}]val = Table[FindRoot[pfun[s], {s, s0}], {s0, {0.9, 1.9, 2}}]Plot[Evaluate[psol[s][t] /. val], {t, 0, 10}]求典型谐波振荡器
,其中
的所有特征值
和特征函数
. 通过探索可能的参数值开始:
psol = ParametricNDSolveValue[{y''[x] == -λ^2 y[x], y[0] == 0, y'[0] == λ}, y, {x, 0, 1}, {λ}];Plot[Evaluate@Table[Tooltip[psol[λ][x], λ], {λ, π / 2, 11π / 2, π / 2}], {x, 0, 1}]pfun = ParametricNDSolveValue[{y''[x] == -λ^2 y[x], y[0] == 0, y'[0] == λ}, y[1], {x, 0, 1}, {λ}];Plot[pfun[λ], {λ, π / 2, 11π / 2}]sol = Table[FindRoot[pfun[λ] == 0, {λ, λ0}], {λ0, {3, 6, 9, 12, 16}}]//QuietPlot[Evaluate[psol[λ][x] /. sol], {x, 0, 1}]求量子谐振子
,
,
的前三个特征函数. 开始于绘制
的解,其中
:
pfun = ParametricNDSolveValue[{-y''[x] + x ^ 2 y[x] == λ y[x], y[0] == 0, y'[0] == 1}, y, {x, -15, 15}, {λ}];Plot[Evaluate@Table[pfun[λ][x], {λ, 0, 13, 1}], {x, -5, 5}, PlotRange -> {-2, 2}]Plot[pfun[λ][5]Exp[-5], {λ, 0, 13}, PlotRange -> {-7, 7}]Map[FindRoot[pfun[λ][5], {λ, #}]&, {2.8, 6.5, 10}]Show[Plot[Evaluate@Table[pfun[λ][x], {λ, 0, 13, 1}], {x, -5, 5}, PlotRange -> {-1, 1}, PlotStyle -> Lighter[Gray, .5]], Plot[{pfun[3][x], pfun[7][x], pfun[11][x]}, {x, -5, 5}]]ψ[n_, x_] := (HermiteH[n, x] E^-(x^2/2)/Sqrt[2^n n! Sqrt[π]])Plot[{ψ[1, x], -ψ[3, x], ψ[5, x]}, {x, -5, 5}, PlotRange -> {-1, 1}]求
,
的解具有最小弧长度时,
的值,其中
到
. 开始绘制
的值为 0 到 1 的解:
pfun = ParametricNDSolveValue[{y''[t] + y[t] == 3a Sin[y[t]], y[0] == y'[0] == 1, α'[t] == Sqrt[1 + y[t] ^ 2], α[0] == 0}, {y[t]}, {t, 0, 10}, {a}];
alfun = ParametricNDSolveValue[{y''[t] + y[t] == 3a Sin[y[t]], y[0] == y'[0] == 1, α'[t] == Sqrt[1 + y[t] ^ 2], α[0] == 0}, α[10], {t, 0, 10}, {a}];Plot[Evaluate@Table[Tooltip[pfun[a], a], {a, 0, 1, .1}], {t, 0, 10}]Plot[alfun[a], {a, 0, 1}, MaxRecursion -> 0, PlotPoints -> 100]Show[Plot[Evaluate@Table[pfun[a], {a, 0, 1, .1}], {t, 0, 10}, PlotRange -> All, PlotPoints -> 500, PlotStyle -> Lighter[Gray, 0.3]], Plot[pfun[0], {t, 0, 10}, PlotStyle -> Thick]]lmin = FindMinimum[alfun[a], {a, 0.725}, AccuracyGoal -> 7]Show[Plot[Evaluate@Table[pfun[a], {a, .65, .8, .005}], {t, 0, 10}, PlotRange -> All, PlotPoints -> 500, PlotStyle -> Lighter[Gray, 0.3]], Plot[pfun[a] /. lmin[[2]], {t, 0, 10}, PlotStyle -> Thick]]求解径向形式的 Klein-Gordon 方程,势能形式为
:
sol = ParametricNDSolveValue[{Derivative[2][R][r] - ((1 - (UnitConvert[Quantity[1, "FineStructureConstant"]] E^-r Z + ϵ)^2) R[r]) == 0, R[0] == 0, R'[0] == 1}, R, {r, 0, 50}, {ϵ, Z}]ContourPlot[sol[ϵ, Z][50] == 0, {Z, 50, 800}, {ϵ, -1, 1}, FrameLabel -> Automatic, PlotPoints -> 100]Subscript[v, 1][t_] := (Sign[t - .01] + 1) / 2;components = {r iR[t] == Subscript[v, 2][t] - Subscript[v, 3][t], l iL'[t] == Subscript[v, 1][t] - Subscript[v, 2][t], iC[t] == c Subscript[v, 3]'[t]};
connections = {iV[t] - iL[t] == 0, iL[t] - iR[t] == 0, iR[t] - iC[t] == 0};
ic = {iR[0] == 0, iL[0] == 0, iC[0] == 0, Subscript[v, 2][0] == 0, Subscript[v, 3][0] == 0};pfun = ParametricNDSolveValue[{components, connections, ic}, Subscript[v, 2], {t, 0, .03}, {r, l, c}];step = Plot[Subscript[v, 1][t], {t, 0, .03}, Filling -> {1 -> 0}, Ticks -> {Range[0.01, 0.03, 0.01], Automatic}]Show[step, Plot[Evaluate@Table[pfun[r, 10^-2, 10^-4][t], {r, {5, 10, 20, 40}}], {t, 0, .03}], PlotRange -> All]Show[step, Plot[Evaluate@Table[pfun[10, 10^-2l, 10^-4][t], {l, {.25, 1, 2}}], {t, 0, .03}], PlotRange -> All]Show[step, Plot[Evaluate@Table[pfun[10, 10^-2, 10^-4c][t], {c, {.25, 1, 2}}], {t, 0, .03}], PlotRange -> All]参数灵敏度 (5)
pfun = ParametricNDSolveValue[{y''[t] + y[t] == a Sin[2t ] + Cos[2y[t]], y[0] == 1, y'[0] == 0}, y, {t, 0, 10}, {a}];Show[Plot[Evaluate@Table[pfun[a][t], {a, -.6, .6, .1}], {t, 0, 5}, PlotStyle -> Lighter[Gray, 0.3], PlotRange -> All], Plot[pfun[0][t], {t, 0, 5}]]Plot[Evaluate[pfun[0][t] + {-.5, 0, .5}pfun'[0][t]], {t, 0, 5}, PlotStyle -> {Gray, {Blue}, Gray}, Filling -> {1 -> {3}}]pfun = ParametricNDSolveValue[{θ''[t] + (9.8 / 10)Sin[θ[t]] == -(a / 10)ω ^ 2 Sin[ω t]Sin[θ[t]], θ[0] == 3.14158, θ'[0] == 0.01}, θ, {t, 0, 5}, {ω, a}];if = pfun[50, 2];
ifa = D[pfun[ω, a], a] /. {ω -> 50, a -> 2};Plot[Evaluate[if[t] + {-.1, 0, .1}ifa[t]], {t, 0, 5}, PlotStyle -> {Gray, Blue, Gray}, Filling -> {1 -> {3}}]ndf = ParametricNDSolveValue[{Derivative[1][x][t] == -3 (x[t] - y[t]), Derivative[1][y][t] == -x[t] z[t] + a x[t] - y[t], Derivative[1][z][t] == x[t] y[t] - z[t], x[0] == z[0] == 0, y[0] == 1}, x[T], {t, 0, T}, {a, T}, MaxSteps -> ∞];Plot[Evaluate[RealExponent[D[ndf[a, 8], a]]], {a, 26, 27}, PlotRange -> All]pfun = ParametricNDSolveValue[{D[u[t, x], t] == c^2 D[u[t, x], x, x], u[0, x] == Exp[-(a x) ^ 2], u[t, -10] == u[t, 10] == 0}, u, {t, 0, 5}, {x, -10, 10}, {a, c}];ifun = pfun[1, 1];
ifda = D[pfun[a, 1], a] /. {a -> 1};
ifdc = D[pfun[1, c], c] /. {c -> 1};Panel@Grid[Join[{{"", "a", "c"}}, Table[{Row[{"t=", τ}], Plot[Evaluate[(ifun[τ, x] + .5{0, 1, -1}ifda[τ, x])], {x, -10, 10}, Filling -> {2 -> {3}}, PlotRange -> All], Plot[Evaluate[(ifun[τ, x] + .5{0, 1, -1}ifdc[τ, x])], {x, -10, 10}, Filling -> {2 -> {3}}, PlotRange -> All]}, {τ, {1, 3, 5}}]]]ColorSensitivityPlot3D[f_, fsense_, opts___] :=
Block[{fs = fsense}, Plot3D[f, {t, 0, 5}, {x, -10, 10}, Mesh -> None, ColorFunction -> Function[{t, x}, ColorData["LakeColors"][fs]], PlotPoints -> 60, ColorFunctionScaling -> False, opts]]{ColorSensitivityPlot3D[pfun[1, 1][t, x], 1.5Abs[ifda[t, x]], PlotLabel -> a, PlotRange -> All], ColorSensitivityPlot3D[pfun[1, 1][t, x], Abs[ifdc[t, x]], PlotLabel -> c, PlotRange -> All]}pfun = ParametricNDSolveValue[{D[u[t, x], t, t] == c ^ 2 D[u[t, x], x, x], u[0, x] == Exp[-(a x) ^ 2], Derivative[1, 0][u][0, x] == 0, u[t, -10] == u[t, 10]}, u, {t, 0, 5}, {x, -10, 10}, {a, c}];ifun = pfun[1, 1];
ifda = D[pfun[a, 1], a] /. {a -> 1};
ifdc = D[pfun[1, c], c] /. {c -> 1};Panel@Grid[Join[{{"", "a", "c"}}, Table[{StringJoin["t = ", ToString[τ]], Plot[Evaluate[(pfun[a, c][τ, x] + .5{0, 1, -1}D[pfun[a, c][τ, x], a]) /. {a -> 1, c -> 1}], {x, -10, 10}, Filling -> {2 -> {3}}, PlotRange -> All], Plot[Evaluate[(pfun[a, c][τ, x] + .5{0, 1, -1}D[pfun[a, c][τ, x], c]) /. {a -> 1, c -> 1}], {x, -10, 10}, Filling -> {2 -> {3}}, PlotRange -> All]}, {τ, {1, 3, 5}}]]]ColorSensitivityPlot3D[f_, fsense_, opts___] :=
Block[{fs = fsense}, Plot3D[f, {t, 0, 5}, {x, -10, 10}, Mesh -> None, ColorFunction -> Function[{t, x}, ColorData["LakeColors"][fs]], PlotPoints -> 60, ColorFunctionScaling -> False, opts]]{ColorSensitivityPlot3D[pfun[1, 1][t, x], Abs[ifda[t, x]], PlotLabel -> a, PlotRange -> All], ColorSensitivityPlot3D[pfun[1, 1][t, x], .25Abs[ifdc[t, x]], PlotLabel -> c, PlotRange -> All]}参数拟合 (2)
{sol, samples} = NDSolve[{y''[t] == -9.8, y[0] == 1, y'[0] == 40, WhenEvent[Mod[t, .5] == 0, Sow[{t, y[t]}]]}, y, {t, 0, 10}]//Reap;
noisysamples = Map[({#[[1]], #[[2]] + RandomReal[{-10, 10}]})&, First@samples];ListPlot[noisysamples]pfun = ParametricNDSolveValue[{y''[t] == -w y[t], y[0] == a, y'[0] == b}, y, {t, 0, 10}, {w, a, b}];fit = FindFit[noisysamples, pfun[w, a, b][t], {{w, .1}, {a, 1}, {b, 1}}, t]Plot[pfun[w, a, b][t] /. fit, {t, 0, 10}, Epilog -> {Point@noisysamples}]pfun = ParametricNDSolveValue[{y''[t] == -g, y[0] == p, y'[0] == v}, y, {t, 0, 10}, {g, p, v}];fit = FindFit[noisysamples, pfun[g, p, v][t], {{g, 5}, {p, .5}, {v, .5}}, t]Plot[pfun[g, p, v][t] /. fit, {t, 0, 10}, Epilog -> {Point@noisysamples}]time = Quantity[{0, 25, 34, 42, 54, 63, 80, 89, 103, 115, 131, 145, 158, 175, 195, 213, 225, 250, 274, 298, 315, 335, 353, 387, 411, 440, 475, 492, 520, 530, 550, 560, 570, 585, 600, 610, 620, 630, 640, 647, 660, 670, 680, 690, 700, 710, 720, 730, 740, 750, 760, 770, 778, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000, 1010, 1020, 1030, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 1110, 1120, 1130, 1140, 1150, 1160, 1170, 1180, 1190, 1200, 1210, 1220, 1230, 1240, 1250, 1260, 1270, 1280, 1300, 1340, 1356, 1380, 1418, 1725, 1740, 1825, 1890, 1955, 2022, 2077, 2160, 2244, 2320, 2408, 2473, 2613}, "Seconds"];
temp = Quantity[{210, 204, 200, 198, 196, 194, 192, 190, 188, 186, 184, 182, 180, 178, 176, 174, 172, 170, 168, 166, 164, 162, 160, 158, 156, 154, 152, 150, 150, 148, 148, 147, 146, 145, 144, 144, 144, 143, 143, 142, 142, 141, 141, 140, 140, 139.5, 139, 139, 138, 138, 137, 137, 136, 136, 136, 135, 135, 134, 134, 133, 133, 133, 132.5, 132, 132, 131, 131, 131, 130, 130, 129.5, 129, 129, 128.5, 128, 128, 128, 127.5, 127, 127, 126, 126, 126, 125.5, 125, 125, 124.5, 124, 124, 123.5, 123, 123, 122.5, 122, 122, 122, 121.5, 121, 121, 121, 120.5, 120.5, 120, 120, 119, 118, 117, 116, 111, 110.5, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99}, "DegreesFahrenheit"];tempK = UnitConvert[temp, "Kelvins"];
Subscript[tempK, 0] = QuantityMagnitude[First[tempK]];
Subscript[tempK, ∞] = QuantityMagnitude[UnitConvert[Quantity[79, "DegreesFahrenheit"], "Kelvins"]];
tend = QuantityMagnitude[Last[time]];BoltzmannConstant = Quantity[1.3806504`*^-23 , "Joules" / "Kelvins"];
c = QuantityMagnitude[(2260 18/6.02 10^23 BoltzmannConstant)];pfun = ParametricNDSolveValue[{(Derivative[1][T][t] == -k1(T[t] - Subscript[tempK, ∞]) - k2 (E^-c / T[t] - E^-c / Subscript[tempK, ∞])), T[0] == Subscript[tempK, 0]}, T, {t, 0, tend}, {k1, k2}];fitdata = N@QuantityMagnitude[Transpose[{time, tempK}]];fit = FindFit[fitdata, pfun[k1, k2][t], {{k1, 0.0001}, {k2, 10000}}, t]Show[ ListPlot[fitdata], Plot[Evaluate[pfun[k1, k2][t] /. fit], {t, 0, tend}, PlotStyle -> Red]]属性和关系 (3)
使用 NDSolveValue 求解带有参数的微分方程:
ndsvfun[a_] := NDSolveValue[{y''[t] == -a y[t] + t Sin[y[t]], y[0] == 1, y'[0] == 1}, y, {t, 0, 100}];Table[First@AbsoluteTiming[ndsvfun[1][100]], {10}]ParametricNDSolve 缓存解并接着重新使用缓存的解的值:
pfun = ParametricNDSolveValue[{y''[t] == -a y[t] + t Sin[y[t]], y[0] == 1, y'[0] == 1}, y, {t, 0, 100}, {a}];Table[First@AbsoluteTiming[pfun[1][100]], {10}]DSolve 可以解析式求解带有参数的某些微分方程:
dsol = y[x] /. First@DSolve[{y'[x] + a y[x] == 1, y[0] == 1}, y[x], x]使用 ParametricNDSolveValue 数值求解范例:
ndsol = ParametricNDSolveValue[{y'[x] + a y[x] == 1, y[0] == 1}, y, {x, 0, 5}, {a}, MaxStepSize -> 0.01];Plot[Evaluate[{D[dsol, a], D[ndsol[a][x], a]} /. a -> 1], {x, 0, 5}]使用 SystemModelParametricSimulate 模拟更大的分层系统模型:
pf = SystemModelParametricSimulate[\!\(\*GraphicsBox[«8»]\), "Inertia2.w", 40, {"Resistor1.R", "SpringDamper1.d"}]sims = {pf[0.1, 0.25], pf[0.4, 0.3]};Plot[Evaluate@Through[sims[t]], {t, 0, 40}]可能存在的问题 (1)
用 WhenEvent、Reap 和 Sow 采样的解只试用对每个参数值的第一次调用:
pfun = ParametricNDSolveValue[{y''[t] == -a Cos[ y[t]], WhenEvent[Mod[t, 1], Sow[{t, y[t]}]], y[0] == 1, y'[0] == 1}, y, {t, 0, 10}, {a}]{ifun, {points}} = pfun[10]//ReapPlot[ifun[t], {t, 0, 10}, Epilog -> {PointSize[Medium], Red, Point[points]}]{ifun, points} = pfun[10]//ReapPlot[ifun[t], {t, 0, 10}, Epilog -> {PointSize[Medium], Red, Point[points]}]相关指南
-
▪
- 微分方程 ▪
- 偏微分方程 ▪
- 符号向量、矩阵和数组
文本
Wolfram Research (2012),ParametricNDSolveValue,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ParametricNDSolveValue.html (更新于 2014 年).
CMS
Wolfram 语言. 2012. "ParametricNDSolveValue." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2014. https://reference.wolfram.com/language/ref/ParametricNDSolveValue.html.
APA
Wolfram 语言. (2012). ParametricNDSolveValue. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ParametricNDSolveValue.html 年
BibTeX
@misc{reference.wolfram_2026_parametricndsolvevalue, author="Wolfram Research", title="{ParametricNDSolveValue}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/ParametricNDSolveValue.html}", note=[Accessed: 17-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_parametricndsolvevalue, organization={Wolfram Research}, title={ParametricNDSolveValue}, year={2014}, url={https://reference.wolfram.com/language/ref/ParametricNDSolveValue.html}, note=[Accessed: 17-June-2026]}