Mathematica returns non-numerical integrand while minimizing

  • Thread starter Thread starter physstudent.4
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
SUMMARY

The discussion centers on minimizing the function Etrial[a] defined in Mathematica, specifically using the NIntegrate function for numerical integration. The user initially attempted to minimize Etrial[a] using NMinimize, Minimize, and FindMinimum, but faced issues with non-numerical integrands. The solution involves switching from NIntegrate to Integrate for closed-form expressions, which significantly enhances performance. Additionally, redefining the trial function to depend on both x and a allows for easier handling of partial derivatives in Mathematica.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of numerical integration techniques in Mathematica
  • Knowledge of calculus, specifically derivatives and integrals
  • Experience with optimization methods in mathematical programming
NEXT STEPS
  • Learn how to use Mathematica's Integrate function for closed-form solutions
  • Explore the differences between NMinimize and Minimize in Mathematica
  • Study partial derivatives and their application in optimization problems
  • Investigate performance optimization techniques in Mathematica for complex functions
USEFUL FOR

Mathematics students, researchers in computational mathematics, and anyone using Mathematica for optimization and integration tasks will benefit from this discussion.

physstudent.4
Messages
12
Reaction score
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
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.
 
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!
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 34 ·
2
Replies
34
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 43 ·
2
Replies
43
Views
6K