linopy.piecewise.tangent_lines#
- linopy.piecewise.tangent_lines(x, x_points, y_points)#
Compute tangent-line (chord) expressions for a piecewise linear function.
Low-level helper returning a
LinearExpressionwith an extra piece dimension. Each element along the piece dimension is the chord of one piece: \(m_k \cdot x + c_k\). No auxiliary variables are created.For most users: prefer
add_piecewise_formulation()with a bounded tuple(y, y_pts, "<=")/(y, y_pts, ">=")— it builds on this helper and adds thex ∈ [x_min, x_max]domain bound plus a curvature-vs-sign check that catches the “wrong region” case. Usetangent_linesdirectly only when you need to compose the chord expressions manually (e.g. with other linear terms, or without the domain bound).t = tangent_lines(power, x_pts, y_pts) m.add_constraints(fuel <= t) # upper bound (concave f) m.add_constraints(fuel >= t) # lower bound (convex f)
- Parameters:
x (
VariableorLinearExpression) – The input expression.x_points (
BreaksLike) – Breakpoint x-coordinates (must be strictly monotonic; both ascending and descending are accepted).y_points (
BreaksLike) – Breakpoint y-coordinates.
- Returns:
LinearExpression– Expression with an additional_breakpoint_piecedimension (one entry per piece).- Warns:
EvolvingAPIWarning –
tangent_linesis part of the newly-added piecewise API; the returned expression shape and piece-dim name may be refined. Silence withwarnings.filterwarnings("ignore", category=linopy.EvolvingAPIWarning).