
Untitled
By: a guest on
May 17th, 2012 | syntax:
None | size: 0.74 KB | hits: 8 | expires: Never
How to tell Mathematica to replace 0 to power 0 by 1?
f = (#1^#2) &
f[0,0]
f = (If[#1 == 0 && #2 == 0, 1, #1^#2]) &
a x^n0 + b y^n1 + c x^n2 y^n3
Manipulate[Row[{format[x, n], "=", eval[x, n]}],
{{x, 0.0, "x="}, 0, 1, .1, Appearance -> "Labeled"},
{{n, 0.0, "n="}, 0, 1, .1, Appearance -> "Labeled"},
Initialization :>
(
format[x_, n_] := HoldForm["(" x ")"^n];
eval = Unevaluated[#1^#2] /. HoldPattern[0.0^0.0] :> 0.0 &
)
]
f = Unevaluated[#1^#2] /. HoldPattern[0^0] :> 1 &
z2zProtect[Function[body_]] :=
Function[Unevaluated[body] /. HoldPattern[0^0] :> 1]
f = z2zProtect[#1^#2 &]
ff = z2zProtect[#1^#2 + 2 #2^#3 + 3 #3^#4 &]
In[26]:= ff[0,0,0,0]
Out[26]= 6
Clear[f];
f[0, 0] = 1;
f[a_, b_] := a^b;