segmentedFunction

Creates a new piecewise linear function.

Syntax

This function uses the syntax depicted in the following diagram:

In order to simplify code generation, a trailing comma is allowed.

Parameters

  • The first parameter is a pair of floating-point values (s0, y0).
  • The remaining parameters are triples of floating-point values (xi, yi, si) sorted by xi.

Description

This function creates a new piecewise linear function. Each parameter (pair or triple) represents one segment of the function. The segments are defined by splitting points x1, x2,.. xn, values at the splitting point y0, y1,.. yn and slopes of the segments s0, s1,.. sn:

The segments of the function are:

Segment number Definition interval Function value at t
0 (-∞, x1) y0 + s0 (t - x1)
i=1,2,.. n-1 [xi, xi+1) yi + si (t - xi)
n [xn, ∞) yn + sn (t - xn)

The function is always defined on (-∞, ∞), however it does not have to be continuous (in the example above the function is discontinuous at x1 and x3.

If only a single pair (s0, y0) is specified, then s0 must be 0 and the result is constant function that has value y0 everywhere.

Example


function = segmentedFunction((-1, 5), (10, 0, 0), (15, 5, 3));

The code above creates function with the following graph:

Requirements

  • The segments must be sorted in ascending order by xi.
  • Two segments with the same value xi are not allowed.

Notes