The simulation of my Modelica model gets aborted right at the beginning with the following reason:
The arguments u_min and u_max provided in the function call
solveOneNonlinearEquation(f,u_min,u_max)
do not bracket the root of the single non-linear equation 0=f(u)
fa and fb must have opposite sign which is not the case
The values of fa and fb, calculated at the beginning of the simulation, are indeed of the same sign. I looked up the function Modelica tried to call, but I am not sure if I understood the reason for Modelica raising this error. If someone would explain to me why this function Modelica.Math.Nonlinear.solveOneNonlinearEquation
needs opposite signs for fa and fb and what could cause fa and fb to have the same sign, I would be really glad. You would help me to get a deeper understanding of how Modelica works.
Thanks in advance for the help, Paul
To give some more details on the perfectly correct comment:
The function Modelica.Math.Nonlinear.solveOneNonlinearEquation
looks for the point at which the output of the function f
is crossing the value zero. This point is called the "the root" of the function. A function can have none, a single or multiple roots. The number of root can depend on the search interval.
When the function has the same sign at both borders at the interval, it is possible that there is no root in the function, which is why an error is returned. It would be possible that there is an even number of roots, but this is not guaranteed. Still, having opposite signs at the borders does not guarantee that there is only a single root.
As an example: A sinus (which is available as Modelica.Math.Nonlinear.Examples.UtilityFunctions.fun4
) will have three zero crossings when setting the interval to [-5, 5]:
Looking for the root between -5
and 5
, therefore has three correct solutions for and it is not obvious which one will be the return value. Calling:
Modelica.Math.Nonlinear.solveOneNonlinearEquation(function Modelica.Math.Nonlinear.Examples.UtilityFunctions.fun4(), -5,5);
will return 0
, but the value could be +pi
or -pi
as well.
In contrast finding the root with different limits [-5,-1]:
Modelica.Math.Nonlinear.solveOneNonlinearEquation(function Modelica.Math.Nonlinear.Examples.UtilityFunctions.fun4(), -5,-1);
will give -3.141592653589793
, which is the only solution given the limits.
Finally, doing the same for [-4,2]
Modelica.Math.Nonlinear.solveOneNonlinearEquation(function Modelica.Math.Nonlinear.Examples.UtilityFunctions.fun4(), -4, 2);
will trigger the error you get:
The arguments u_min and u_max provided in the function call
solveOneNonlinearEquation(f,u_min,u_max)
do not bracket the root of the single non-linear equation 0=f(u):
u_min = -4
u_max = 2
fa = f(u_min) = 0.756802
fb = f(u_max) = 0.909297
fa and fb must have opposite sign which is not the case
To not trigger the error, you need to make sure that at all point in your simulation, the values at the limits have opposite signs.