Problems 9
  1. Theory.

    1. How do you pass your integrand to gsl_integration_qags rutine?
    2. What are the arguments epsabs, epsrel and abserr (correspondingly the 4th, 5th and last argument) of gsl_integration_qags rutine?
    3. What does gsl_integration_qags return?
    4. How does gsl_integration_qags return the calculated result?
    5. Does gsl_integration_qags estimates the error of the calculated result?
    6. Suppose you integrand does not take any extra parameters: what du you do then with the .params member of the corresponding gsl_function structure?
    7. What is the limit argument (the 4th argument) of the gsl_integration_qagi rutine?
    8. What is the argument of the gsl_integration_workspace_alloc function?
    9. Do you need to free any memory having finished with your gsl_integration_qag* integrations?
    10. Suppose your C-function returns an integer value, like gsl_integration_qags function, which you would normally call as

      int flag = gsl_integration_qags(arguments);

      can you call the function simply as

      gsl_integration_qags(arguments);

      ?
    11. Suppose you need to calculate an integral with a given requirement to absolute error. How do you then set up your parameters of gsl_integration_qags routine?
  2. Practice: numerical integration with Gauss-Kronrod algorithms.

    1. In the variational method in quantum mechanics one calculates the expectation value E[ψ] of a Hamiltonian H,

      E[ψ] ≡ ⟨ψ|H|ψ⟩/⟨ψ|ψ⟩ ,

      with some trial function ψ. The trial function is then optimized to provide the minimum of the expectation value.

      Consider the Hamiltonian operator for one-dimensional oscillator,

      Ho = - (1/2) (d²/dx²) + (1/2) x² ,

      and the trial function in the form of a Gaussian,

      ψα(x) = exp(-αx²/2) ,

      where α is the variational parameter. Calculate numerically

      E(α) ≡ ⟨ψα|Hoα⟩/⟨ψαα⟩ .

      and plot the result – you should see a minimum of E=0.5 at α=1 (why?).

      Hints:

      1. The norm-integral, ⟨ψαα⟩, has the form (check it)

        ⟨ψαα⟩ = ∫-∞ exp(-αx²) dx .

        It is actually analytic, but you have to calculate it numerically.
      2. The Hamiltonian-integral, ⟨ψα|Hoα⟩, has the form (check it also)

        ⟨ψα|Hoα⟩ = ∫-∞ (-α²x²/2 + α/2 + x²/2)*exp(-αx²) dx .

        It is actually also analytic, but you again have to calculate it numerically.
      3. Since the integration limits are infinite, you migh want to use gsl_integration_qagi function.