compute_work: Compute Area Under the Curve (AUC) Using Trapezoidal...

View source: R/compute_work.R

compute_workR Documentation

Compute Area Under the Curve (AUC) Using Trapezoidal Integration

Description

This function calculates the area under the curve (AUC) using the trapezoidal rule from the 'pracma' package. It also supports computing the positive AUC (sum of areas above the x-axis) and negative AUC (sum of areas below the x-axis).

Usage

compute_work(time, power, type = "total")

Arguments

time

A numeric vector representing the x-coordinates of the data points, typically time in seconds.

power

A numeric vector representing the y-coordinates of the data points, typically power in watts.

type

A character string specifying the type of AUC to compute. Options are "total", "positive", or "negative". Default is "total".

Value

A numeric value representing the computed AUC based on the specified type.

Examples

# Example time and power data
time <- c(1, 2, 3, 4, 5)
power <- c(-2, 3, 5, -7, 6)
# Compute total AUC
auc_total <- compute_work(time, power, type = "total")
print(auc_total)
# Compute positive AUC
auc_positive <- compute_work(time, power, type = "positive")
print(auc_positive)
# Compute negative AUC
auc_negative <- compute_work(time, power, type = "negative")
print(auc_negative)

Kneerav/biomechanics documentation built on March 30, 2025, 12:56 a.m.