Qu

sin

Builtin index · Core maths

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.

CodeInputOutputDescription
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.

x = 0 to 9
plot(x, sin(x / 2))
output
· plot: figure 10 (10 points)
-1 0 1 2 3 4 5 0 1 2 3 4 5 6 7 8 9 Styled panel

from plotting

x = 0 to 9
plot(x, sin(x / 2), "o")
output
· plot: figure 11 (10 points)
-1 0 1 2 3 4 5 0 1 2 3 4 5 6 7 8 9 x=0, y=0 x=1, y=0.479 x=2, y=0.841 x=3, y=0.997 x=4, y=0.909 x=5, y=0.598 x=6, y=0.141 x=7, y=-0.351 x=8, y=-0.757 x=9, y=-0.978 Styled panel

from plotting

n = 0 to 255
x = sin(n * 0.1) + 0.05 * randn(256)
spectrum_mag = x |> fft |> abs
smoothed = spectrum_mag |> dct |> idct

from numerics-dsp

t = (0 to 4095) / 10000
v = 1.2 * sin(2 * pi * 101 * t) + 2.048

c = adc(v, bits = 12, vmin = 0, vmax = 4.096)
print("LSB {c.lsb * 1000:.3f} mV, clipped {c.clipped}, ideal SNR {c.snr_ideal:.1f} dB")
output
LSB 1.000 mV, clipped 0, ideal SNR 74.0 dB

from noise

How it works

sin/cos/tan/asin/acos/atan/sinh/cosh are complex-aware, on the same route as tanh/exp/log/sqrt (map1_complex): real input still takes the real function (a real value outside a real domain, e.g. asin(2), stays NaN rather than silently promoting to complex -- same convention as sqrt(-1)), and an explicit Value::Complex/ CVec/CMat argument takes the complex branch. See Complex64::{sin,cos,tan,asin,acos,atan,sinh,cosh} in qu-core for the identities. sin/cos/sinh/cosh are entire (no poles anywhere in the plane); tan's poles are exactly the real-axis ones real tan already has (see Complex64::tan's doc comment for the proof); asin/acos have branch points at z = +-1. None of these error at a pole/branch point -- Complex64::div already yields non-finite components there, matching the float semantics the rest of the runtime uses (sqrt(-1) doesn't error either).

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.

See also

cos, tan — documented in the same entry.