MultiRootFinder returns Error using 3 equations

ROOT Version: 5.34/36
Platform: Windows 10 64bit
Compiler: Microsoft Visual Studio 2015

Good afternoon,
I am new to the forum and please forgive my nooby mistakes.
So: My task is to write a program with differential equations later on. But right now I am struggling with the steady state variables. I want to use the GSLMultiRootFinder solution (class? function?, not completely sure which one it is). So Basically I have the 3 equations as show below and the cling tells me:

Error in <ROOT::Math::GSLMultiRootFinder::Solve>: Error initializing the solver

Equation 2 is not necessarily needed, but for future reference I’d like to know what my mistake is.

// possible changable parameters
double c0_as = 0.74;    
double F_as  = 3  /1000/60;     
double F_ws  = 40 /1000/60;    
double T_in  = 295.15;          
double Vr    = 298 /1000;       

// constant parameters
const double rho_a  = 1082;    
const double M_a    = 102.9;  
const double n      = 1;     
const double EA     = 44.35;  
const double k_inf  = 139390;  
const double d_Hr   = -55.5;    
const double rhocp  = 4.186;   
//const double R      = 8.314;  
const double R = TMath::R() /1000; 

const double F_s = F_as + F_ws;

void Test()
    // x[0] = concentration A
    // x[1] = concentration B
    // x[2] = temperature
    //TF2 *dcdt = new TF2("dcdt","F_s/Vr *(c0_as - x[0]) - k_inf*exp(-EA /R  /x[2])*x[0]");
    TF3 *dcdt   = new TF3("dcdt","[0]/[1]*([2]   - x[0]) - [3]  *exp(-[4]/[5]/x[2])*x[0]");
    dcdt->SetParameters(          F_s,Vr,  c0_as,          k_inf,     EA, R);

    //TF2 *dcESdt = new TF2("dcESdt","-F_s/Vr *x[1] + 2*k_inf*exp(-EA /R  /x[2])*x[0]");
    TF3 *dcESdt   = new TF3("dcESdt","-[0]/[1]*x[1] + 2*[2]  *exp(-[3]/[4]/x[2])*x[0]");
    //dcESdt->SetParameters(             F_s,Vr,          k_inf,     EA, R);

    //TF2 *dTdt = new TF2("dTdt","F_s/Vr *(T_in - x[2]) + (-d_Hr)/rhocp*k_inf*exp(-EA /R  /x[2])*x[0]");
    TF3 *dTdt   = new TF3("dTdt","[0]/[1]*([2]  - x[2]) + (-[3]) /[4]  *[5]  *exp(-[6]/[7]/x[2])*x[0]");
    dTdt->SetParameters(          F_s,Vr,  T_in,            d_Hr, rhocp,k_inf,     EA, R);

    ROOT::Math::WrappedMultiTF1 g1(*dcdt,3);
    ROOT::Math::WrappedMultiTF1 g2(*dcESdt,3);
    ROOT::Math::WrappedMultiTF1 g3(*dTdt,3);
    ROOT::Math::GSLMultiRootFinder r;

    // Startwerte
    double x0[3] = {0.5*c0_as, 1.5*c0_as, T_in};

   // cout << r.Root() << endl;

Intrestingly, if I change the program to just the 2 equations (1 and 3, also using TF2 instead of TF3), I do get results, but the results are signifficant different to the one I’ve calculated beforehand in Matlab. The solution I get with Matlab is (0.3700 1.1100 295.1500).

I am looking forward to be part of this stunning forum :smiley:

Ok, I have found my mistake :sweat_smile:
First of all I’ve been sloppy with my datatype. Obviously calculation shouls be casted as double.

And in addition to that, I forget to uncomment the SetParameters

And last point, of course the results in Matlab are not the same as the start values.

They are supposed to be (0.3490 0.7821 300.3346).

Thank you for your kind waiting :grinning:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.