# NIntegrate can't integrate function but work fine with the expression [closed]

I have a function called psi0 that looks like this: psi0 := E^(-(x - 10)^2/10) and I'm trying to integrate it numerically from 0 to a variable L. However, I keep getting and error saying

NIntegrate::inumr: The integrand e^(-(1/10) (-10+x)^2) has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,10.}}.


I'm using NIntegrate like this: NIntegrate[psi0[x], {x, 0, L}] when I get this error but if I do this: NIntegrate[E^(-(x - 10)^2/10), {x, 0, L} it works perfectly fine. What's going wrong with the function?

• You write psi0 := then call it using psi0[x] ? May 4 at 23:20
• Sorry I'm new to mathematica, how would I fix this? May 4 at 23:24
• Please see below. May 4 at 23:25
• e is not defined as a System  symbol, but E is, representing the exact value of the base of the natural logarithm. The letter e appears in the warning message, but the letter E appears in the code that works perfectly fine. May 8 at 17:07

L = 10;
psi0 := E^(-(x - 10)^2/10)
NIntegrate[psi0[x], {x, 0, L}] You can't call psi0[x] when the function is defined as psi0:= E^(-(x - 10)^2/10) . You need to define the function as actually taking an argument x for Mathematica to find it and use it.

I set L=10 since you did not show what L was.

Try the following

Clear["Global*"]
L = 10;
psi0[x_] := E^(-(x - 10)^2/10)
NIntegrate[psi0[x], {x, 0, L}]

(*2.80247*)


Btw, you do not numerical integrate on this, Mathematica can solve it analytically

Clear["Global*"]
psi0[x_] := E^(-(x - 10)^2/10)
sol = Integrate[psi0[x], {x, 0, L}] sol /. L -> 10 N[%] • What does Clear["Global*"] do? May 4 at 23:26
• @AnikPatel it just clears all your variables and other definitions from the notebook so they do not mess up anything in the following calculation. May 4 at 23:27
• How can I make the integral a function? Like if have a function f(n,x) and I want g(n) to be the integral of f(n,x)dx from 0 to L? May 5 at 0:00
• @AnikPatel if I understand you write, may be like this? !Mathematica graphics May 5 at 0:04
• I got it, I wasn't clearing the function and it was screwing me up May 5 at 0:04