cos
result = sin(x)
Input: x · Output: result
What it is
Standard trigonometric functions, computed elementwise. x is the input angle in radians — a scalar, a Vec of any length, or a Mat/Signal of any shape.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = sin(x) | x scalar, Vec, Mat, or Signalnot documented yet | result — | Returns exactly the same type and shape as x, one trig value per element. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
# `grid` does not depend on `p`, so building it per call is waste.
grid = outer(f, t) # K x N, built ONCE
shape(p) := sum(A .* cos(grid + p), axis = 0)
from numerics-dsp
N = 8
n = 0 to N - 1
x = cos(2 * pi * 2 * n / N) # a pure tone at bin 2
X = fft(x, N)
print("mag = {abs(X)}")
output
mag = [2.449294e-16, 3.463824e-16, 4, 3.463824e-16, 2.449294e-16, 3.463824e-16, 4, 3.463824e-16]
from numerics-dsp
K = 4
N = 64
Fs = 64
bins = [2, 5, 11, 17]
f = bins * (Fs / N)
t = 0 to (N - 1) / Fs step 1/Fs
f as vector(K, 1) # frequency column (K,1)
t as vector(1, N) # time row (1,N)
phase = 2 * pi * f * t # (K,1)*(1,N) -> (K,N), one row per tone
A = ones(K, 1) / sqrt(K) # unit-RMS amplitude per tone
x = sum(A .* cos(phase), axis=0) # sum the tones down the rows
from numerics-dsp
t = linspace(0, 1, 50)
plot(t, sin(t))
plot(t, cos(t))
legend("sin(x)", "cos(x)")
output
· plot: figure 3 (50 points) · plot: figure 4 (50 points)
from plotting