• Gurobi Staff

Hi,

The hyperbolic sine function equals $$\sinh(x) = \frac{e^{x} - e^{-x}}{2}$$. You can use the method Model.addGenConstrExp() to model the natural exponential function. See the example script below:

import gurobipy as gpfrom gurobipy import GRBm = gp.Model()sinh = m.addVar(lb=-GRB.INFINITY, name="sinh")# It is important to set the lb and ub of the x and x_minus variables # to the tightest possible values depending on your applicationx = m.addVar(lb=-GRB.INFINITY, name="x")x_minus = m.addVar(lb=-GRB.INFINITY, name="x_minus")y = m.addVar(name="y")y_minus = m.addVar(name="y_minus")# Define y = exp(x)m.addGenConstrExp(x, y)# Define y_minus = exp(x_minus) = exp(-x)m.addGenConstrExp(x_minus, y_minus)# Define the relationship between x and x_minusm.addConstr(x == -1*x_minus)# Define hyperbolic sine functionm.addConstr(sinh == 0.5 * (y - y_minus))

Best regards,

Maliheh

Hello Ms. Maliheh,

I have just noticed that a mistake has been made on your shared code;

which I think should be like the following; (please correct me if I am wrong).

# Define the relationship between x and x_minus
m.addConstr(x_minus == -1*x)

Best Regard,

• Gurobi Staff

Hi,

If you multiply both sides of the constraint $$x_{\text{minus}} = - x$$ by -1, we get the constraint $$-x_{\text{minus}} = x$$. Therefore, your version is mathematically equivalent to the constraint implemented in our script.

Best regards,

Maliheh