LinearInterp

Revision as of 00:34, 30 October 2015 by Karenlee (talk | contribs) (merged with user guide)

LinearInterp(d, r, x, ,i)

Given coordinates «d» and «r», indexed by «i», it returns the y value corresponding to «x», interpolated linearly between the two values of «d» nearest to «x». The numbers in «d» must be in increasing order. If «d» is itself a simple index, «r» must be indexed by «d», and parameter «i» may be omitted. Otherwise, «i» must be a common index of «d» and «r». «x» may be a scalar or have any dimensions. If «x» is less than the smallest (and first) value in «d» (x < d[@i=1]), it returns that smallest value r[@i=1]. Similarly, if «x» is larger than the last (largest) value in «d» (x > d[@i=Size(i)]), it returns that largest value r[@i=Size(i)]. Values of «d» and «r» should be numbers or Null. It ignores any Null values, interpolating between the nearest values of «d» and «r» that contain numbers.

LinearInterp-graph.png

Examples

The following example uses the Example Interpolation Variables:

Linearinterp(Index_b, Array_a, 1.5, Index_b) →

Index_a ▶
a b c
2 -2.5 2

Optional Parameters

i

Specifies the common index of «d» and «r». You can omit this, if «d» is itself an index of «r».

extrapolationMethod

Specifies the value to return if «x» is outside the values of «d»:

  • 1: Use the «r» for nearest «d» (default method)
  • 2: Return Null.
  • 3: Use the «r» value for the nearest point during evaluation, but disallow extrapolation while solving an LP or QP optimization.
  • 4: Extrapolate by extending the slope of the first or last segment.
  • 5: Extrapolate by extending the slope of the first or last segment, but disallow extrapolation while solving an LP or QP optimization.

Example usage:

LinearInterp(d, r, x, i, extrapolationMethod:4 )
LinearInterp ExtrapolationMethod4.png

Piecewise-linear relationships in Optimizations

(Applies to Analytica Optimizer edition)

LinearInterp can be used inside a linear and quadratic optimization problem, known as a Linear Program (LP), Quadratic Program (QP) or Quadratically Constrained Program (QCP). When the «d» and «r» parameters do not depend on any decision variables, but «x» is a function of decision variables, the structured optimization facility (i.e., DefineOptimization) will automatically incorporate the piecewise-linear relationship into your LP, keeping the problem linear (or quadratic if already quadratic).

Since a continuous non-linear scalar function y=f(x) can be approximated by a piecewise-linear function, this makes it possible to approximate non-linear relationships inside an LP. Structured optimization accomplishes this by introducing auxiliary (decision) variables and constraints into the optimization formulation. This happens transparently, so you don't have to figure out how to do it yourself, but since some of the variables are boolean-valued, it creates a combinatoric search space for the LP engine. This often increases search times dramatically. Hence, it may not be a panacea for solving your non-linear problem. Nonetheless, there can still be advantages to keeping your problem an LP (rather than having to resort to an NLP). LPs are always array-abstractable, and when an optimal solution is returned, you can be assured it really is the global optimum.

The example model "Vacation plan with PWL tax.ana", found in the Optimizer Example folder in Analytica 4.6 and later, illustrates an example of LinearInterp in an optimization problem. In the example, a graduated income tax rate is modeled in a piecewise-linear fashion using LinearInterp in the context of a linear program.

(new to Analytica 4.6) When solving an optimization problem, extrapolation adds complexity to the formulation, so if you know that «x» (at the optimum) will always be within the range of «d»'s values, it is probably advantageous to disable extrapolation. This is done by specifying the «extrapolationMethod» parameter to be either 2, 3 or 5. When you use any of these options, the resulting formulation implicitly constraints «x» to be within the range of «d». If you are wrong about «x» being in that range, your problem might become infeasible (because of the extra constraint).

History

See Also

Comments


You are not allowed to post comments.