How to use algebra_solver


I am trying to use algebra_solver, but couldn’t get the code right. Any help on the issue is greatly appreciated!

Here is my function and then try to solve it.

  vector algebra_system(vector effpi,vector theta, real[] x_r, int[] x_i){
                 vector[1] rslt;
                 rslt[1]=(theta[1]+theta[2]/effpi[1]+theta[3]/effpi[1]^2) - (theta[4]+theta[5]*effpi[1]);
                 return rslt;
  real desrfunc (real effpi, 
             real toxpi, 
             vector param,
             real[] x_r,
             int[] x_i){
               real a = param[1];
               real b = param[2];
               real c = param[3];

               real rhop;
               real rhoq;
               real desr;
               vector[1] effpi0;
               real toxpi0;
               vector[1] effpi_guess=[0.5]';
               vector[5] param_ex=append_row(append_row(param, -toxpi/(effpi-1)), toxpi/(effpi-1));
               effpi0 = algebra_solver(algebra_system, effpi_guess, param_ex, x_r, x_i);
               toxpi0 = a + b/effpi0[1] + c/effpi0[1]^2;
               desr =(rhop>0)? rhoq/rhop-1: -500;
               return desr;

The algebra solver needs to know that x_r and x_i are data. You must mark them in the function signature

real desrfunc (real effpi, 
           real toxpi, 
           vector param,
           data real[] x_r,
           data int[] x_i){
1 Like

This solves the problem! Thank you!