Skip to main content

hyperbolic sine of the elements of X

Answered

Comments

3 comments

  • Maliheh Aramon
    Gurobi Staff 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 gp
    from gurobipy import GRB

    m = 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 application
    x = 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_minus
    m.addConstr(x == -1*x_minus)
    # Define hyperbolic sine function
    m.addConstr(sinh == 0.5 * (y - y_minus))

    Best regards,

    Maliheh

    1
  • Abde
    Conversationalist
    First Question

    Hello Ms. Maliheh,

    Thank you so much for your feedback, it is really helpful.

    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,

    0
  • Maliheh Aramon
    Gurobi Staff 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

    0

Please sign in to leave a comment.