Skip to main content

numerical value - Could I define 0^0 to be 1?




Many occasions, where I need to work numerically with functions. For a variable strictly between 0 and 1, during the optimization, it could become 0.^0 or 0^0, which then become indeterminate.enter image description here


Is there a way to define this 0^0=1?


What are the possible down side of defining such relationship?


Thanks!



Answer



With the help of @Michael E2 in my question


Case $\frac{0}{0}$


In this case,you can define your function like this:


func1[a_,b_]:=0 /;b==0
func1[a_,b_]:=a/b


Test


func1[0, 0]


1

Case$0.^0$


So you can use the /; to avoid $0.^0$


func2[x_,0]:=1/;x==0||x==0.

func2[x_,y_:0]:=x^y

Test


 func2[0, 0]


1

 func2[0., 0]



1

Comments