Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to tell Mathematica to replace 0 to power 0 by 1?
  2. f = (#1^#2) &
  3.        
  4. f[0,0]
  5.        
  6. f = (If[#1 == 0 && #2 == 0, 1, #1^#2]) &
  7.        
  8. a x^n0 + b y^n1 + c x^n2 y^n3
  9.        
  10. Manipulate[Row[{format[x, n], "=", eval[x, n]}],
  11.  {{x, 0.0, "x="}, 0, 1, .1, Appearance -> "Labeled"},
  12.  {{n, 0.0, "n="}, 0, 1, .1, Appearance -> "Labeled"},
  13.  Initialization :>
  14.   (
  15.    format[x_, n_] := HoldForm["(" x ")"^n];
  16.    eval = Unevaluated[#1^#2] /. HoldPattern[0.0^0.0] :> 0.0 &
  17.    )
  18.  ]
  19.        
  20. f = Unevaluated[#1^#2] /. HoldPattern[0^0] :> 1 &
  21.        
  22. z2zProtect[Function[body_]] :=
  23.    Function[Unevaluated[body] /. HoldPattern[0^0] :> 1]
  24.        
  25. f = z2zProtect[#1^#2 &]
  26.        
  27. ff = z2zProtect[#1^#2 + 2 #2^#3 + 3 #3^#4 &]
  28.  
  29. In[26]:= ff[0,0,0,0]
  30. Out[26]= 6
  31.        
  32. Clear[f];
  33. f[0, 0] = 1;
  34. f[a_, b_] := a^b;