View Raw SPL
/*****************************************************************************
* *
* HAVERSIN.SPL Copyright (C) 2020 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Evaluates a haversin function *
* *
* Revisions: 12 May 2020 RRR Creation *
* *
*****************************************************************************/
#if @HELP_HAVERSIN
HAVERSIN
Purpose: Calculates the haversin of any expression.
Syntax: HAVERSIN(val)
val - A scalar, series or table.
Returns: A scalar, series or table depending on the input value.
Example:
W1: haversin(0..pi/100..2*pi)
Generates the haversin from 0 to 2*pi radians.
Example:
t = 0..0.01..1;
haversin(2*pi*3*t);
Create a 101 point series of a 3 Hz haversin sampled at 100
samples per second.
Remarks:
The haversin function is defined as:
haversin(theta) = sin(theta/2)^2 = (1 - cos(theta)) / 2
See GHAVERSIN to generate a haversin with a specified length
and delta x.
See Also:
Ghaversin
Gsin
Sin
#endif
/* evaluates a haversin function */
haversin(theta)
{
if (argc < 1) error(sprintf("%s - input required", __FUNC__));
return(0.5 * (1 - cos(theta)));
}