Difficulty using boost quadrature library

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Difficulty using boost quadrature library

Boost - Users mailing list
Hello everyone,

I'm new to using boost and I'm trying to use its quadrature routines, specifically
the tanh_sinh integrator. I'm trying to run the examples here:


I've been successful using it with the double datatype. However, I can't seem to work with the Real datatype. When I run the following, I'm successful.
tanh_sinh<double> integrator;
auto f = [](double x) { return 5*x + 7; };
double Q = integrator.integrate(f);
Q = integrator.integrate(f, 0.0, 1.1);

But when I run the following:
auto f = [](Real x) { return log(x)*log(1-x); };
Real Q = integrator.integrate(f, (Real) 0, (Real) 1);
I get the error:

boost_test.cxx: In function ‘int main(int, char**)’:
boost_test.cxx:47:15: error: ‘Real’ has not been declared
  auto f2 = [](Real x) { return log(x)*log(1-x); };
               ^~~~
boost_test.cxx:48:2: error: ‘Real’ was not declared in this scope
  Real Q2 = integrator.integrate(f2, (Real) 0, (Real) 1);


I think I need to include the right headers for this to go away. However, I'm not sure what the correct header file is.

Thank you for your attention.

--
Anirban Pal




_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Difficulty using boost quadrature library

Boost - Users mailing list

You need to decide on which Real type you want, perhaps

 

#include <boost/multiprecision/cpp_bin_float.hpp>

 

and then chose perhaps a quad precision type like cpp_bin_float_quad for 128-bit precision

 

You can then either use a typedef to define Real

 

typedef cpp_bin_float_quad Real;

 

or pass cpp_bin_float_quad as a template parameter into your own function.

 

HTH

 

Paul

 

PS It would be nice if we had a fully worked example?

 

 

 

From: Boost-users <[hidden email]> On Behalf Of Anirban Pal via Boost-users
Sent: 14 August 2020 01:08
To: [hidden email]
Cc: Anirban Pal <[hidden email]>
Subject: [Boost-users] Difficulty using boost quadrature library

 

Hello everyone,

 

I'm new to using boost and I'm trying to use its quadrature routines, specifically

the tanh_sinh integrator. I'm trying to run the examples here:


 

I've been successful using it with the double datatype. However, I can't seem to work with the Real datatype. When I run the following, I'm successful.

tanh_sinh<double> integrator;
auto f = [](double x) { return 5*x + 7; };
double Q = integrator.integrate(f);
Q = integrator.integrate(f, 0.0, 1.1);

 

But when I run the following:

auto f = [](Real x) { return log(x)*log(1-x); };
Real Q = integrator.integrate(f, (Real) 0, (Real) 1);

I get the error:

 

boost_test.cxx: In function ‘int main(int, char**)’:
boost_test.cxx:47:15: error: ‘Real’ has not been declared
  auto f2 = [](Real x) { return log(x)*log(1-x); };
               ^~~~
boost_test.cxx:48:2: error: ‘Real’ was not declared in this scope
  Real Q2 = integrator.integrate(f2, (Real) 0, (Real) 1);

 

I think I need to include the right headers for this to go away. However, I'm not sure what the correct header file is.

 

Thank you for your attention.

 

--

Anirban Pal

 

 

 


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Difficulty using boost quadrature library

Boost - Users mailing list
In reply to this post by Boost - Users mailing list

On 14/08/2020 01:07, Anirban Pal via Boost-users wrote:

> Hello everyone,
>
> I'm new to using boost and I'm trying to use its quadrature routines,
> specifically
> the *tanh_sinh* integrator. I'm trying to run the examples here:
>
> <goog_14736225>
> https://www.boost.org/doc/libs/1_66_0/libs/math/doc/html/math_toolkit/double_exponential/de_tanh_sinh.html 
> <https://www.boost.org/doc/libs/1_66_0/libs/math/doc/html/math_toolkit/double_exponential/de_tanh_sinh.html>
>
> I've been successful using it with the *double* datatype. However, I
> can't seem to work with the *Real* datatype. When I run the following,
> I'm successful.
> tanh_sinh<double>  integrator;
> auto  f  =  [](double  x)  {  return  5*x  +  7;  };
> double  Q  =  integrator.integrate(f);
> Q  =  integrator.integrate(f,  0.0,  1.1);
>
> But when I run the following:
> auto  f  =  [](Real  x)  {  return  log(x)*log(1-x);  };
> Real  Q  =  integrator.integrate(f,  (Real)  0,  (Real)  1);

I confess that's not the best example in the docs :(

The name "Real" is just used as "some kind of floating point type" -
replace with whatever actual type you wish to use.

> I get the error:
>
> boost_test.cxx: In function ‘int main(int, char**)’:
> boost_test.cxx:47:15: error: ‘Real’ has not been declared
>   auto f2 = [](Real x) { return log(x)*log(1-x); };
>                ^~~~
> boost_test.cxx:48:2: error: ‘Real’ was not declared in this scope
>   Real Q2 = integrator.integrate(f2, (Real) 0, (Real) 1);
>
> I think I need to include the right headers for this to go away.
> However, I'm not sure what the correct header file is.
>
> Thank you for your attention.
>
> --
> Anirban Pal
>
>
>
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Difficulty using boost quadrature library

Boost - Users mailing list
Thank you. That worked.

On Fri, 14 Aug 2020 at 05:23, John Maddock via Boost-users <[hidden email]> wrote:

On 14/08/2020 01:07, Anirban Pal via Boost-users wrote:
> Hello everyone,
>
> I'm new to using boost and I'm trying to use its quadrature routines,
> specifically
> the *tanh_sinh* integrator. I'm trying to run the examples here:
>
> <goog_14736225>
> https://www.boost.org/doc/libs/1_66_0/libs/math/doc/html/math_toolkit/double_exponential/de_tanh_sinh.html
> <https://www.boost.org/doc/libs/1_66_0/libs/math/doc/html/math_toolkit/double_exponential/de_tanh_sinh.html>
>
> I've been successful using it with the *double* datatype. However, I
> can't seem to work with the *Real* datatype. When I run the following,
> I'm successful.
> tanh_sinh<double>  integrator;
> auto  f  =  [](double  x)  {  return  5*x  +  7;  };
> double  Q  =  integrator.integrate(f);
> Q  =  integrator.integrate(f,  0.0,  1.1);
>
> But when I run the following:
> auto  f  =  [](Real  x)  {  return  log(x)*log(1-x);  };
> Real  Q  =  integrator.integrate(f,  (Real)  0,  (Real)  1);

I confess that's not the best example in the docs :(

The name "Real" is just used as "some kind of floating point type" -
replace with whatever actual type you wish to use.

> I get the error:
>
> boost_test.cxx: In function ‘int main(int, char**)’:
> boost_test.cxx:47:15: error: ‘Real’ has not been declared
>   auto f2 = [](Real x) { return log(x)*log(1-x); };
>                ^~~~
> boost_test.cxx:48:2: error: ‘Real’ was not declared in this scope
>   Real Q2 = integrator.integrate(f2, (Real) 0, (Real) 1);
>
> I think I need to include the right headers for this to go away.
> However, I'm not sure what the correct header file is.
>
> Thank you for your attention.
>
> --
> Anirban Pal
>
>
>
>
> _______________________________________________
> Boost-users mailing list
> [hidden email]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users

--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users


--
Anirban Pal




_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users