This forum has been archived. All content is frozen. Please use KDE Discuss instead.

customize operator()

Tags: None
(comma "," separated)
kwurpi
Registered Member
Posts
1
Karma
0
OS

customize operator()

Sun Jan 05, 2014 5:34 pm
Hi,
I'd like to solve a non-linear System using Eigen.
I got the class "Model" which defines "int operator() .."

Code: Select all
model.h
    int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvec) const ;

model.cpp
int Model::operator()(const VectorXd &x, VectorXd &fvec) const
    {
        fvec[0]=x[0]-x[1]-x[2];
        fvec[1]=100-(x[0]/7-3)*(x[0]/7-3);
        fvec[2]=(x[1]/20)*(x[1]/20)-(x[2]/25)*(x[2]/25);

        return 0;
    }

Above code works fine, but needs a fvec to be predefined.

Assume I had another class "Loop" which defines "setM" and "getDP" and a container-list
"loopList_" of "Loop"s to process. One equation per Loop.

Code: Select all
int Model::operator()(const VectorXd &x, VectorXd &fvec) const {

    std::list<Loop*>::const_iterator it = loopList_.begin();

    int i = 0;

    for ( ; it != loopList_.end() ; ++it, ++i) {
        Loop* loop = *it;
        (*loop).setM(x[i]);
    }

    for ( it = loopList_.begin(), i = 0 ; it != loopList_.end() ; ++it, ++i) {
        Loop* loop = *it;
        fvec[i]=(*loop).getDP();
    }
}


But this doesnt work because the debugger says: loopList_ is <not accessible>
Probably "const" is the troublemaker, but I don't know what to do next.
Any idea?
thanks
kwurpi
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: customize operator()

Mon Jan 06, 2014 9:31 pm
maybe loopList_ is private? if so make it protected.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]