Note that there are some explanatory texts on larger screens.

plurals
  1. POGSL integration of a class member function
    primarykey
    data
    text
    <p>I have a class called Universe. The class includes a member function to calculate distance and requires numerically integrating an ugly looking function. I was trying to use GSL to perform the integration but I get the following error when I attempt to compile the library - </p> <pre><code>$ g++ -c -O3 -std=c++11 Universe.cpp -o Universe.o $ error: cannot convert ‘Universe::Hz’ from type ‘double (Universe::)(double, void*)’ to type ‘double (*)(double, void*)’ </code></pre> <p>Here's the class Universe without the constructors (for brevity):</p> <h2>Universe.h</h2> <pre><code>#ifndef UNIVERSE_H #define UNIVERSE_H #include &lt;cmath&gt; #include &lt;gsl/gsl_integration.h&gt; using namespace std; class Universe { private: static constexpr double c = 299792458.0, Mpc2Km = 3.08567758e+19, Yrs2Sec = 3.15569e7; double H0 = 67.77, OmegaM = (0.022161+0.11889)/(H0*H0), OmegaL = 0.6914, OmegaG = 8.24e-5, OmegaK = 0.0009; double Ez(double z); double Hz(double z, void* params); public: double distH, timeH; Universe() = default; Universe(double h0); Universe(double omegaM, double omegaL); Universe(double h0, double omegaM, double omegaL); Universe(double omegaM, double omegaL, double omegaG, double omegaK); Universe(double h0, double omegaM, double omegaL, double omegaG, double omegaK); //double radius(); //double age(); double distC(double z); }; #endif </code></pre> <h2>Universe.cpp</h2> <pre><code>#include &lt;cmath&gt; #include &lt;gsl/gsl_integration.h&gt; #include "Universe.h" using namespace std; double Universe::Hz(double z, void* params) { double result = 1.0/pow(OmegaL + pow(1.0+z,3.0)*OmegaM + pow(1.0+z,4.0)*OmegaG + pow(1.0+z,2.0)*OmegaK, 0.5); return result; } double Universe::distC(double z) { double lower_limit = 0.0, abs_error = 1.0e-8, rel_error = 1.0e-8, alpha = 0.0, result, error; gsl_integration_workspace *work_ptr = gsl_integration_workspace_alloc(1000); gsl_function Hz_function; void* params_ptr = &amp;alpha; Hz_function.function = Universe::Hz; Hz_function.params = params_ptr; gsl_integration_qags(&amp;Hz_function, lower_limit, z, abs_error, rel_error, 1000, work_ptr, &amp;result, &amp;error); return distH*result; } </code></pre> <p>I don't quite know how to troubleshoot this problem and I'm using GSL for the first time based on the documentation at: <a href="http://www.gnu.org/software/gsl/manual/html_node/Numerical-integration-examples.html" rel="nofollow">http://www.gnu.org/software/gsl/manual/html_node/Numerical-integration-examples.html</a> and the following guide: <a href="http://www.physics.ohio-state.edu/~ntg/780/gsl_examples/qags_test.cpp" rel="nofollow">http://www.physics.ohio-state.edu/~ntg/780/gsl_examples/qags_test.cpp</a> Thank you for looking and any answers! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload