这是一个奇怪的结果,在此示例中函数定义为“functionB”。有人可以解释一下吗?我想绘制functionB[x]
and functionB[Sqrt[x]]
,它们一定是不同的,但是这段代码表明functionB[x] = functionB[Sqrt[x]]
,这是不可能的。
model = 4/Sqrt[3] - a1/(x + b1) - a2/(x + b2)^2 - a3/(x + b3)^4;
fit = {a1 -> 0.27, a2 -> 0.335, a3 -> -0.347, b1 -> 4.29, b2 -> 0.435,
b3 -> 0.712};
functionB[x_] := model /. fit
Show[
ParametricPlot[{x, functionB[x]}, {x, 0, 1}],
ParametricPlot[{x, functionB[Sqrt[x]]}, {x, 0, 1}]
]
functionB[x]
必须不同于functionB[Sqrt[x]]
,但在这种情况下,两行是相同的(这是不正确的)。
如果你试试?functionB
,你会看到它存储为functionB[x_]:=model/.fit
。因此,每当你现在有functionB[y]
,对于任何y
, Mathematica 评估model/.fit
,得到4/Sqrt[3] - 0.335/(0.435 + x)^2 + 0.347/(0.712 + x)^4 - 0.27/(4.29 + x)
.
这与使用有关SetDelayed
(i.e., :=
)。的右方为functionB[x_]:=model/.fit
每次 Mathematica 看到该模式时都会重新评估f[_]
。您已命名该模式x
是无关紧要的。
你想要的可以通过例如来实现functionC[x_] = model /. fit
。也就是说,通过使用Set
(=
) 而不是SetDelayed
(:=
),从而评价rhs。
希望这足够清楚(可能不是)......
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)