Skip to contents

This function enforces constraints on a parabolic fit for ascending melatonin concentration data. The constraints ensure that the fitted parabola passes through a specified point of interest (POI) and maintains a positive slope in the ascending segment.

Usage

nl_constraints(params, poi_x, poi_y, x)

Arguments

params

A numeric vector of length 3 representing the parabola parameters:

  • a: Quadratic coefficient.

  • b: Linear coefficient.

  • c: Constant term.

poi_x

Numeric. The x-coordinate of the point of interest (POI).

poi_y

Numeric. The y-coordinate of the POI.

x

Numeric vector of x-values representing the ascending segment.

Value

A list containing:

  • pass_poi: The squared deviation from the constraint that the parabola must pass through the POI.

  • pos_grad: The squared deviation from the constraint ensuring a positive slope at the last ascending point.

Details

The function imposes two constraints:

  1. Passing through POI: Ensures the fitted parabola satisfies \(y = ax^2 + bx + c\) at poi_x, poi_y.

  2. Positive Slope: Ensures \(\frac{dy}{dx} = 2ax + b\) remains non-negative at the last x-value.

If the minimum slope at the last ascending point is negative, it is forced to zero as a penalty.

See also

objective_function, which utilizes these constraints during optimization.

Examples

params <- c(0.1, 2, 3)  # Example parabola: y = 0.1x^2 + 2x + 3
poi_x <- 5
poi_y <- 15
x_values <- seq(4, 6, by = 0.5)
constraints <- nl_constraints(params, poi_x, poi_y, x_values)
print(constraints)
#> $pass_poi
#> [1] 0.25
#> 
#> $pos_grad
#> [1] 0
#>