Mathematica returns non-numerical integrand while minimizing

  • Thread starter physstudent.4
  • Start date
  • Tags
    Mathematica
In summary, the conversation discusses minimizing the function Etrial[a], which is defined using the trial function trial[x_] := E^(-a*x^2). The attempts to minimize the function include using NMinimize, Minimize, and FindMinimum, as well as writing a separate loop. It is suggested to use Integrate instead of NIntegrate and to write the trial function as a function of both x and a, which can make it easier for Mathematica to handle.
  • #1
physstudent.4
13
0

Homework Statement


I need to minimize the function Etrial[a]
trial[x_] := E^(-a*x^2)
Etrial[a_] :=
NIntegrate[1/2*D[trial[x], x]^2 + x^4*trial[x]^2, {x, -\[Infinity], \[Infinity]}]/
NIntegrate[trial[x]^2, {x, -\[Infinity], \[Infinity]}]


Homework Equations





The Attempt at a Solution


I have used NMinimize[Etrial[a],a] and Minimize[Etrial[a],a], as well as FindMiminum[Etrial[a],{a,.5}], since when I plot it, the minimum is pretty obviously around .7, so I arbitrarily chose .5 as a close starting point.
 
Physics news on Phys.org
  • #2
Use Integrate instead of NIntegrate. Also, you can actually do the integrals and write the expressions down in closed form. If you define Etrial using those results, it'll be a lot faster since Mathematica won't have to repeatedly perform the integrations.
 
  • #3
I ended up just writing a separate loop that found the minimum. I discovered if I had written my trial function as a function of both x and a, then used partial derivatives, Mathematica can handle that easier. Thanks anyway though!
 

FAQ: Mathematica returns non-numerical integrand while minimizing

Why does Mathematica return a non-numerical integrand error while minimizing?

Mathematica returns a non-numerical integrand error while minimizing because it is unable to find a numerical solution for the integral. This can happen if the function being integrated is too complex or if there are issues with the input parameters.

How can I fix the non-numerical integrand error in Mathematica?

To fix the non-numerical integrand error in Mathematica, you can try simplifying the function being integrated, double-checking the input parameters, and adjusting the integration method or options. You can also try using the NIntegrate function instead of Integrate to find a numerical solution.

Can a non-numerical integrand error be caused by incorrect syntax?

Yes, a non-numerical integrand error can be caused by incorrect syntax in Mathematica. Make sure that all parentheses and brackets are properly closed, and all functions and variables are spelled correctly. Even a small typo can result in a non-numerical integrand error.

Is it possible to get a non-numerical integrand error even if the function being integrated is simple?

Yes, it is possible to get a non-numerical integrand error even if the function being integrated is simple. This can happen if the input parameters are not specified correctly or if there are issues with the integration method or options.

Can external libraries or packages cause a non-numerical integrand error in Mathematica?

Yes, external libraries or packages can cause a non-numerical integrand error in Mathematica. If the function being integrated relies on a library or package, make sure it is properly loaded and compatible with your version of Mathematica. If necessary, try updating the library or package to see if it resolves the error.

Similar threads

Replies
13
Views
2K
Replies
1
Views
2K
Replies
34
Views
4K
Replies
1
Views
895
Replies
4
Views
2K
Replies
6
Views
5K
Replies
7
Views
2K
Back
Top