Curve fitting function doesn't work for (-tanh(w[0]))^x


On Igor, I am trying to write my own fitting function, which will look something like this: (given w[0] = 2)

f(x) = ((-tanh(w[0]))^x)

For some reasons, once I have the above in the expression, the curve fitting function becomes nan. The Graph Now button gives an empty plot.

I also tried:

w[0]^x works

((-tanh(w[0]))*x) works

w[0]*((-tanh(1))^x) also works

(-tanh(w[0]))^x fails


So it seems something is happening when I have power of a tanh. Appreciated if you can provide me with some ideas what the cause is.

The below is the function for the fitting if you would like to try:

Function secSqueeze(w,x) : FitFunc
    Wave w
    Variable x

    //CurveFitDialog/ These comments were created by the Curve Fitting dialog. Altering them will
    //CurveFitDialog/ make the function less convenient to work with in the Curve Fitting dialog.
    //CurveFitDialog/ Equation:
    //CurveFitDialog/ if (mod(x+2,2)>0)
    //CurveFitDialog/   f(x) = 0
    //CurveFitDialog/   else
    //CurveFitDialog/   f(x) = (1/sqrt(cosh(squeezing)))*(-tanh(squeezing))^(x/2)*sqrt(factorial(2*(x/2)))/(2^(x/2)*factorial((x/2)))
    //CurveFitDialog/   endif
    //CurveFitDialog/ End of Equation
    //CurveFitDialog/ Independent Variables 1
    //CurveFitDialog/ x
    //CurveFitDialog/ Coefficients 1
    //CurveFitDialog/ w[0] = squeezing

////The actual function
//  if (mod(x+2,2)>0)
//      return 0
//      else
//      return ((1/sqrt(cosh(w[0])))*(-tanh(w[0]))^(x/2)*sqrt(factorial(2*(x/2)))/(2^(x/2)*factorial((x/2))))^2
//      endif
//  return ((1/sqrt(cosh(w[0])))*(-tanh(w[0]))^x)
    return (-tanh(w[0]))^x


Raising a negative number to a non-integral power gives a complex result:

print cmplx(-tanh(2), 0)^2.5

Your expression is not complex, so Igor returns NaN.