2
$\begingroup$

I have a question that may sound stupid and have an easy answer - but I currently do not see it. I have defined a function of four variables, $f[a,b,c,d]=...$, in what I think is correct Mathematica syntax. I need to evaluate this function at specific values $a*,b*,c*,d*$ for $a, b, c, d$. When I do so, I obtain $Indeterminate$ as a result. However, when I evaluate $f$ at the specific values for $a, c, d$, and only replace $b$ for its value afterwards, $f[a*,b,c*,d*]' /. \{b \rightarrow b*\}$, I do obtain a reasonable result. Any explanation for this?

PS: I can share the snippet, that shouldn't be a problem. However, perhaps there is a general explanation and hence no need for it...? I have seen Setting the parameters in a defined function vs replacement rule in the formula, which basically asks the same question, but I don't think the answer is satisfactory. In any case, thanks in advance.

EDIT: Here goes the expression.

f[h_, s_, a_, b_] := 0.00015034013139827721*h^4*(-12.512450890438938 + Log[0.10272025*RealAbs[h^2]]) - 
   0.00463012409828799*h^4*(-12.512450890438938 + Log[0.49368002148788936*RealAbs[h^2]]) + 
   (3*(14922.284640000005 + 0.4*h^2 - 272.22*s + 0.3818*s^2)^2*(-12.512450890438938 + Log[RealAbs[14922.284640000005 + 0.4*h^2 - 272.22*s + 0.3818*s^2]]))/
    (64*Pi^2) + (1/(256*Pi^2))*(1.5818*h^2 - a - b - 194.44000000000003*s + 1.5826999999999998*s^2 - 
      Sqrt[4*h^2*(-272.22 + 0.7636*s)^2 + (0.8182000000000003*h^2 - a + b - 350.*s - 0.8190999999999999*s^2)^2])^2*
    (-12.512450890438938 + Log[(1/2)*RealAbs[1.5818*h^2 - a - b - 194.44000000000003*s + 1.5826999999999998*s^2 - 
         Sqrt[4*h^2*(-272.22 + 0.7636*s)^2 + (0.8182000000000003*h^2 - a + b - 350.*s - 0.8190999999999999*s^2)^2]]]) + 
   (1/(256*Pi^2))*(1.5818*h^2 - a - b - 194.44000000000003*s + 1.5826999999999998*s^2 + 
      Sqrt[4*h^2*(-272.22 + 0.7636*s)^2 + (0.8182000000000003*h^2 - a + b - 350.*s - 0.8190999999999999*s^2)^2])^2*
    (-12.512450890438938 + Log[(1/2)*RealAbs[1.5818*h^2 - a - b - 194.44000000000003*s + 1.5826999999999998*s^2 + 
         Sqrt[4*h^2*(-272.22 + 0.7636*s)^2 + (0.8182000000000003*h^2 - a + b - 350.*s - 0.8190999999999999*s^2)^2]]])

where the specific values would be $h=246.22, s=200, a=-14922.3,b=5678.49$. When this is evaluated, I obtain $Indeterminate$. However, f[246.22, s, -14922.3, 5678.49] /. s -> 200 seems to work just fine (as in an actual numerical value which, as far as I can judge, is correct). I find this very weird.

$\endgroup$
4
  • $\begingroup$ "I can share the snippet, that shouldn't be a problem.": Please do. There is no general explanation for what ostensibly does not look like normal behavior. In general, it is in your best interest to provide as much information as possible in the form of a minimal working example, if you care to have your question answered. $\endgroup$
    – MarcoB
    Jul 7 '20 at 23:28
  • 1
    $\begingroup$ There it goes, thank you for trying to help out. $\endgroup$
    – Al Waurora
    Jul 7 '20 at 23:49
  • $\begingroup$ The expression given ends with a comma. $\endgroup$ Jul 8 '20 at 1:22
  • $\begingroup$ I inserted the comma out of grammar purposes, but I don't evaluate it like that. Nonetheless, I should remove it, it confuses readers. $\endgroup$
    – Al Waurora
    Jul 8 '20 at 8:19
4
$\begingroup$
Clear["Global`*"]

f[h_, s_, a_, b_] := 
  0.00015034013139827721*
    h^4*(-12.512450890438938 + Log[0.10272025*RealAbs[h^2]]) - 
   0.00463012409828799*
    h^4*(-12.512450890438938 + 
      Log[0.49368002148788936*
        RealAbs[h^2]]) + (3*(14922.284640000005 + 0.4*h^2 - 272.22*s + 
         0.3818*s^2)^2*(-12.512450890438938 + 
        Log[RealAbs[
          14922.284640000005 + 0.4*h^2 - 272.22*s + 0.3818*s^2]]))/(64*
      Pi^2) + (1/(256*Pi^2))*(1.5818*h^2 - a - b - 194.44000000000003*s + 
       1.5826999999999998*s^2 - 
       Sqrt[4*h^2*(-272.22 + 0.7636*s)^2 + (0.8182000000000003*h^2 - a + b - 
            350.*s - 0.8190999999999999*s^2)^2])^2*(-12.512450890438938 + 
      Log[(1/2)*
        RealAbs[1.5818*h^2 - a - b - 194.44000000000003*s + 
          1.5826999999999998*s^2 - 
          Sqrt[4*h^2*(-272.22 + 0.7636*s)^2 + (0.8182000000000003*h^2 - a + 
               b - 350.*s - 0.8190999999999999*s^2)^2]]]) + (1/(256*
        Pi^2))*(1.5818*h^2 - a - b - 194.44000000000003*s + 
       1.5826999999999998*s^2 + 
       Sqrt[4*h^2*(-272.22 + 0.7636*s)^2 + (0.8182000000000003*h^2 - a + b - 
            350.*s - 0.8190999999999999*s^2)^2])^2*(-12.512450890438938 + 
      Log[(1/2)*
        RealAbs[1.5818*h^2 - a - b - 194.44000000000003*s + 
          1.5826999999999998*s^2 + 
          Sqrt[4*h^2*(-272.22 + 0.7636*s)^2 + (0.8182000000000003*h^2 - a + 
               b - 350.*s - 0.8190999999999999*s^2)^2]]]);

As you noted, the function is undefined at the point of interest

f[h, s, a, b] /. {h -> 246.22, s -> 200, a -> -14922.3, b -> 5678.49}

(* Indeterminate *)

however,

f[246.22, s, -14922.3, 5678.49] /. s -> 200

(* 1.65537*10^7 *)

This is equivalent to a limiting case,

Limit[f[h, s, a, b], {h, s, a, b} -> {246.22, 200, -14922.3, 5678.49}]

(* 1.65537*10^7 *)

To workaround the issue, Rationalize and Simplify the expression

f2[h_, s_, a_, b_] = f[h, s, a, b] // Rationalize[#, 0] & // Simplify;

then the function is directly defined at the point

f2[h, s, a, b] /. {h -> 246.22, s -> 200, a -> -14922.3, b -> 5678.49}

(* 1.65537*10^7 *)
$\endgroup$
1
  • $\begingroup$ Thank you very much, Bob. $\endgroup$
    – Al Waurora
    Jul 8 '20 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.