This is a strange result with a function defined as "functionB" in this example. Can someone explain this? I want to plot functionB[x]
and functionB[Sqrt[x]]
, they must be different, but this code shows that functionB[x] = functionB[Sqrt[x]]
, which is impossible.
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]
must different from functionB[Sqrt[x]]
, but in this case, the 2 lines are the same (which is incorrect).
If you try
?functionB
, you'll see that it is stored asfunctionB[x_]:=model/.fit
. Thus, whenever you now havefunctionB[y]
, for anyy
, Mathematica evaluatesmodel/.fit
, obtaining4/Sqrt[3] - 0.335/(0.435 + x)^2 + 0.347/(0.712 + x)^4 - 0.27/(4.29 + x)
.This has to do with using
SetDelayed
(i.e.,:=
). The rhs offunctionB[x_]:=model/.fit
is evaluated anew each time Mathematica sees the patternf[_]
. That you have named the patternx
is irrelevant.What you want could be achieved by e.g.
functionC[x_] = model /. fit
. That is, by usingSet
(=
) rather thanSetDelayed
(:=
), so as to evaluate the rhs.Hope this is clear enough (it probably isn't)...
You might want to try defining the model inside functionB so x in both places are related: