# Error while using Algebraic solver

**URL:** <https://discourse.mc-stan.org/t/error-while-using-algebraic-solver/14528>\
**Category:** General\
**Created:** [April 22, 2020, 10:22pm UTC](https://discourse.mc-stan.org/t/error-while-using-algebraic-solver/14528 "2020-04-22T22:22:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Murali\_037](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Murali\_037](https://discourse.mc-stan.org/u/Murali_037)\
**Post date:** [April 22, 2020, 10:22pm UTC](https://discourse.mc-stan.org/t/error-while-using-algebraic-solver/14528/1 "2020-04-22T22:22:30Z")

</div>

Hi Guys,

I am getting this error while using the solver.

Chain 1: Exception: Exception: Exception: algebra\_solver: the norm of the algebraic function is: 0.33599 but should be lower than the function tolerance: 1e-06. Consider decreasing the relative tolerance and increasing the max\_num\_steps.

Any idea how to debug this?

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [April 23, 2020, 7:23am UTC](https://discourse.mc-stan.org/t/error-while-using-algebraic-solver/14528/2 "2020-04-23T07:23:01Z")

</div>

The solver cannot find a solution. Are you sure the equation system always _does_ have a solution? What is the equation you’re trying to solve?

---

<div class="post-metadata">

**Author:** ![Murali\_037](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Murali\_037](https://discourse.mc-stan.org/u/Murali_037)\
**Post date:** [April 23, 2020, 3:07pm UTC](https://discourse.mc-stan.org/t/error-while-using-algebraic-solver/14528/3 "2020-04-23T15:07:14Z")

</div>

its a polynomial equation of the 4th order.

---

<div class="post-metadata">

**Author:** ![Murali\_037](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Murali\_037](https://discourse.mc-stan.org/u/Murali_037)\
**Post date:** [April 23, 2020, 3:12pm UTC](https://discourse.mc-stan.org/t/error-while-using-algebraic-solver/14528/4 "2020-04-23T15:12:43Z")

</div>

However I think the problem is with the ode function part. I am trying to add the control parameters to the ode function. it is giving me an error while calling the ode function saying that the first argument should be a function of type real, real [], and so on…

in my case, the function is already defined as Real [] and all the arguments are correctly specified. Why is it still giving me this error?

---

<div class="post-metadata">

**Author:** ![Murali\_037](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Murali\_037](https://discourse.mc-stan.org/u/Murali_037)\
**Post date:** [April 23, 2020, 3:47pm UTC](https://discourse.mc-stan.org/t/error-while-using-algebraic-solver/14528/5 "2020-04-23T15:47:50Z")

</div>

@nhuurre rel\_tol, abs\_tol and max\_steps should be specified in the ode solver function like this,

integrate\_ode\_bdf(DICdynamics\_Coral, y0\_calib, t0, ts, var\_calib, x\_r, x\_i, rel\_tol, abs\_tol, max\_steps)

but not in the ode function definition?

real[] DICdynamics\_Coral(real t, //time  
real[] y, //state  
real[] var\_fn, //parameters change name to variables  
data real[] x\_r,  
data int[] x\_i){  
// data real abs\_tol,  
// data real max\_steps) {

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [April 23, 2020, 4:56pm UTC](https://discourse.mc-stan.org/t/error-while-using-algebraic-solver/14528/6 "2020-04-23T16:56:18Z")

</div>

That’s correct. The tolerance only affects at what times the solver evaluates the objective function. The function itself does not see the tolerance arguments.

> **[Stan User’s Guide](https://mc-stan.org/docs/2_23/stan-users-guide/coding-an-ode-system.html)**
>
> Stan user’s guide with examples and programming techniques.

> [@Murali\_037](#):
>
> its a polynomial equation of the 4th order.

A general fourth order polynomial could look like this  
 ![4poly](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/f/fce6c14bce5a606e5f6a54ce3dd58c812654dba6.png)

I don’t know exactly how the solver works but I imagine it could get stuck in the local minimum on the right. Also there’s two roots on the left so it might give you the wrong one. It’s important to choose the initial guess close to the solution you want. Of course the particular equation you have may be different.

Generally debugging means inserting [print statements](https://mc-stan.org/docs/2_23/reference-manual/print-statements-section.html#debug-by-print) in the code and figuring out what the parameter values are when things go wrong. If you’re using RStan `expose_stan_functions()` can also help.
