LinA.jl Documentation
LinA.Linearize
— FunctionLinearize(expr_fct::Ef,x1::Real,x2::Real, e::ErrorType; bounding = Best() ::BoundingType, ConcavityChanges = [Inf]::Array{Float64,1})
Makes an optimal piecewise Linear approximation of expr_fct from x1 to x2. The result will be an array of LinearPiece
. Note that the array is directly callable as a function.
Arguments
expr_fct
: function to linearize from R to R (either an expression or a native julia function)x1
: fromx2
: toe
: error type either Absolute() or Relative()
Optional Arguments
bounding
:Under()
for an underestimation,Over()
for an overestimation,Best()
for estimation that can go under or over the function. By default, it usesBest()
ConcavityChanges
: Concavity changes in the function. If not given, they will be computed automatically which, in rare cases, can lead to precision errors if the concavity is asymptotic to zero.
It is also possible to specify which algorithm to use between HeuristicLin()
and ExactLin()
by simply adding it after the error type. By default LinA uses the heuristic.
If the function is given by a expression, the variable is assume to be x
Example
julia> pwl = Linearize(:(x^2),0,2,Absolute(0.1))
3-element Vector{LinA.LinearPiece}:
0.894427190999916 x -0.1 from 0.0 to 0.894427190999916
2.683281572999748 x -1.7000000000000006 from 0.894427190999916 to 1.7888543819998326
4.736067977499794 x -5.372135954999589 from 1.7888543819998326 to 2.0
julia> pwl(1)
0.9832815729997475
LinA.LinearBounding
— FunctionLinearBounding(expr_fct::Ef,x1::Real,x2::Real, e::ErrorType; ConcavityChanges = [Inf]::Array{Float64,1} )
Makes an optimal piecewise Linear underestimation and overestimation of expr_fct from x1 to x2. For certain error types, it can saves a lot of overhead over calling Linearize two times.
Arguments
expr_fct
: function to linearize (either an expresion or a native julia function)x1
: fromx2
: toe
: error type. Both Absolute() and Relative() are implemented.
Optional Arguments
ConcavityChanges
: Concavity changes in the function. If not given, they will be computed automatically which, in rare cases, can lead to precision errors if the concavity is asymptotic to zero.
LinA.LinearizeConvex
— FunctionLinearizeConvex(x1,x2,lower::Function,upper::Function,du::Function)
Makes an optimal piecewise Linear approximation from x1 to x2 of a convex corridor
Arguments
- lower : function at the bottom of the corridor
- upper : function on top of the corridor
- du : derivative of the upper function
LinA.CorridorFromInfo
— FunctionCorridorFromInfo(x1::Real,x2::Real,expr_fct::Ef,e::ErrorType,bounding::BoundingType)
Create a corridor from an error type and bounding style. This corridor is a tuple (start,end,lowerBound, upperbound, derivative of the Upper bound)
Arguments
x1
: fromx2
: toexpr_fct
: function to linearize (either an expresion or a native julia function)e
: error type. Both Absolute() and Relative() are implementedbounding
:Under()
for an underestimation,Over()
for an overestimation,Best()
for estimation that can go under or over the function.
LinA.ExactPiece
— FunctionExactPiece(start::Real,maximum::Real,lower,upper)
Computes the maximal linear piece starting at start
which lies in between lower
and upper
. Works for any continuous lower
and upper
.
Arguments
start
: frommaximum
: maximal end point of the linear segmentlower
: lower bound of the corridorupper
: upper bound of the corridor
LinA.Relative
— TypeRelative error from the function (in percentage)
!!! warning
For a relative error to be well defined, the function needs to have no zeros!
LinA.isContinuous
— FunctionisContinuous(pwl, ε = 1e-5)
Determine whether a pwl function is continuous up to a numerical precision of ε.
Arguments
plw
: pwl functionε
: numerical precision
LinA.CplexBreakpoints
— FunctionCplexBreakpoints(pwl, ε = 1e-5)
Outputs the breakpoints needed for CPLEX to natively model PWL functions.
Arguments
plw
: pwl functionε
: numerical precision