Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#include "MyClass.h"
// Define Class members
// =====================
double MyClass::GetSolution( ) {
// point the pt_MyClass element to this class
p->pt_MyClass = this;
// instantiate a gsl_function ...
gsl_function F;
F.params = p;
// ... and point the address of our
// wrapper to it
F.function = &gslClassWrapper;
std::cout << "at x=2, objective function value is " << gslClassWrapper(2.0,p) << std::endl;
std::cout << "at x=1, objective function value is " << gslClassWrapper(1.0,p) << std::endl;
// set up GSL root solver
const gsl_root_fsolver_type *T;
gsl_root_fsolver *sroot;
T = gsl_root_fsolver_brent;
sroot = gsl_root_fsolver_alloc (T);
double low = -5;
double hi = 5;
double root;
root = find_root(sroot,&F, low , hi );
return root;
}
double MyClass::getC( void ) { return( p->c); } ;
// Define Objective Function
// =========================
double MyClass::obj(double x, void * par) {
gsl_f_pars *p = (gsl_f_pars *)par;
//return x;
//return (p->a * x + p->b) * x + p->c;
return pow(x - p->a , 3);
}
// main routine
// ============
int main(){
MyClass C;
// allocate the param structure
gsl_f_pars myp;
myp.a=1.0;
myp.b= 0;
myp.c=-5;
// point to myp from inside the class
C.setPars( &myp );
std::cout << "checking value of C: " << C.getC() << std::endl;
std::cout << "computing result : " << C.GetSolution() << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.