Bessel Function Evaluation Problem in Mathematica

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 6K views
EngWiPy
Messages
1,361
Reaction score
61
Hello,

When I write:
Code:
BesselK[1,2]

in the Mathematica editor, the output is the same as the input. But I want to evaluate it numerically. In other words, I want the output be a number. How can I do that?

Regards
 
Physics news on Phys.org
Did you try the N function?

Code:
N[BesselK[1,2]]
BesselK[1,2] // N

In general, Mathematica only "evaluates" such functions for special arguments for which it knows exact values. In all other cases, it leaves the answer exact. You can force it to give a decimal representation using
N[expr]
or
N[expr, # of decimals]Another way that often works is to give the arguments as floating numbers rather than exact values:
Code:
BesselK[1., 2]
BesselK[1, 2.]
BesselK[1., 2.]
 
CompuChip said:
Did you try the N function?

Code:
N[BesselK[1,2]]
BesselK[1,2] // N

In general, Mathematica only "evaluates" such functions for special arguments for which it knows exact values. In all other cases, it leaves the answer exact. You can force it to give a decimal representation using
N[expr]
or
N[expr, # of decimals]


Another way that often works is to give the arguments as floating numbers rather than exact values:
Code:
BesselK[1., 2]
BesselK[1, 2.]
BesselK[1., 2.]

Thank you CompuChip, but it didn't work, I still get the same expression. Why?

Regards
 
try again, the N method is correct.

In[30]:= N[BesselK[1, 2]]

Out[30]= 0.139866

make sure its not misspelled.
 
Hepth said:
try again, the N method is correct.

In[30]:= N[BesselK[1, 2]]

Out[30]= 0.139866

make sure its not misspelled.

Now it is working, but believe me, I wrote it correctly, and the result was not produced numerically, I don't know why. Anyway, thank you Hepth very much to confirm the N[] numerical evaluation method.

Regards