![]() (As an aside, the chebfun project hinges on functions being nicely approximated by interpolating polynomials with abscissas that are transformed Chebyshev polynomial roots/extrema.) Legendre, Chebyshev, or any other point distribution which "clusters" near the ends) will generally ensure that you have a quadrature rule that behaves tamely even for large numbers of points. Abscissas that are "nicely distributed" (e.g. Robert's warning of the Runge phenomenon happening is a good one, and it does happen if your abscissas are perversely distributed (relatedly, the underlying Vandermonde matrix is ill-conditioned) the equispaced case being among the worst-behaved point distributions. If not, then use a global variable or a static variable in a function.I have settled this question here in brief, a FORTRAN implementation of algorithms for solving this problem have been published in the Collected Algorithms of the ACM.Īt the risk of being redundant, I'd like to mention here some other things I mentioned in the (now expanded) answer of mine at that other site for completeness' sake. If it's worth it to you, then change the class. Then the argument that you need can be something other than Doub(*)(Doub). If you want to make the Stiel class constructor accept something like a functor that can keep the value of an internal (private) variable like x0, change it to a templated class or create a new templated class with the whatever functionality you need. In my experience, thread-safety is generally not an issue with my programs in which I would be using this class, but that might not always be the case. I agree that a static variable in a public function is not ideal from a picky (thread-safe or other hoity-toity point view). I think that it's easier to trap a spurious function call than put a watch point on some memory location in a debugger-but that depends on your development habits. ![]() There is only one way to change x0 and that is to call the function, whereas with a global variable, a typographical error inside a block of code can inadvertently change the value. In effect, xminusx0 now behaves like an interface to a global variable x0įrom a debugging point of view, I find use of a static variable in a public function less onerous than use of global variables. Stiel gauss(npoints, a, b, ShiftedGaussian, map_semiinf_x, map_semiinf_dxdt) ![]() ![]() XMinusX0(x0, true) // Initialise x0 for ShiftedGaussian Static Doub x0 = 0 // not shifted unless re-initialized with init = true Instead of the functor class that you showed us, maybe you could try something like For your object, the function's return type must be a Doub and it must have one argument that is a Doub. If you don't want to change the class (a Good Decision, I'm thinking), then you must give its constructor an argument that is a pointer to a function. Is there a way of doing this without changing the Stiel class?Haven't you answered your own question? (Actually the compiler answered it for us.) The Stiel class is not templated, so there is no way to use a functor-type argument. The compiler cannot find an appropriate constructor that takes a functor instead of a function. Stiel gauss(npoints,a,b,sg,map_semiinf_x,map_semiinf_dxd t) Void gauss_hermite(const Int npoints, const Doub x0, const Int prec) ShiftedGaussian(const Doub xx0) : x0(xx0) NR_C301/code/stiel.h:1: note: Stiel::Stiel(const Stiel&) NR_C301/code/stiel.h:61: note: Stiel::Stiel(Int, Doub, Doub, Doub, Doub (*)(Doub, Doub)) Stiel_test.cpp:32: error: no matching function for call to ‘Stiel::Stiel(const Int&, Doub&, Doub&, ShiftedGaussian&, Doub (&)(Doub), Doub (&)(Doub))’ Stiel_test.cpp: In function ‘void gauss_hermite(Int, Doub, Int)’: If I replace the functor with a normal function it compiles and works fine. Is there a way of doing this without changing the Stiel class?īelow you'll find the full error message followed by the full test code. However, I ran into trouble in a particular case, when using the Stiel class to obtain abscissas and weights for Gaussian quadrature. The possibility of using functors with many of the NR3 routines is one of the features I love of this new edition.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |