RunMat
GitHub

atan — Element-wise inverse tangent in MATLAB and RunMat.

Y = atan(X) computes the inverse tangent (in radians) of each element in X. It supports real and complex values, and "like" options control output class/residency in MATLAB- and RunMat-compatible forms.

Syntax

Y = atan(X)
Y = atan(X, "like", P)

Inputs

NameTypeRequiredDefaultDescription
XAnyYesInput scalar, array, char array, complex value, or gpuArray.
likeStringScalarYes"like"Output template selector keyword.
PLikePrototypeYesPrototype determining host/gpu residency and real/complex output class.

Returns

NameTypeDescription
YAnyElement-wise inverse tangent result.

Errors

IdentifierWhenMessage
RunMat:atan:InvalidInputInput cannot be interpreted as supported numeric/char/complex data.atan: invalid input
RunMat:atan:InvalidOptionOptional arguments after X are malformed or unsupported.atan: invalid option
RunMat:atan:ArgCountToo many input arguments were supplied.atan: too many input arguments

How atan works

  • Works on scalars, vectors, matrices, and N-D tensors, including logical and integer inputs (which are promoted to double precision before evaluation).
  • Character arrays are interpreted as their Unicode code points and return dense double arrays of identical shape.
  • Complex inputs follow MATLAB's analytic extension atan(z) = (1/(2i)) * (log(1 + i z) - log(1 - i z)), ensuring identical branch behavior and NaN/Inf propagation.
  • Returns results in radians for real inputs and complex numbers for complex inputs.
  • Empty arrays and already scalar values pass straight through while preserving shape.

Does RunMat run atan on the GPU?

When RunMat Accelerate is active and the selected provider implements unary_atan, the runtime keeps tensors on the GPU and executes the kernel entirely on-device.

If the provider lacks unary_atan (or declines the request), RunMat gathers the data to the host, computes the result with the reference implementation, and then reapplies residency requests such as 'like' prototypes automatically.

Fusion planning groups neighboring elementwise operations so downstream kernels can stay on the GPU even if atan itself fell back to the CPU.

GPU memory and residency

Usually you do not need to call gpuArray. When a provider exposes unary_atan, the runtime keeps data on the GPU automatically. If the hook is missing (or if you supply a host 'like' prototype), RunMat gathers and computes on the CPU, then honors the requested residency so you do not have to manage transfers manually.

Examples

Arctangent of a scalar

y = atan(1)

Expected output:

y = 0.7854

Element-wise arctangent of a vector

x = linspace(-2, 2, 5);
angles = atan(x)

Expected output:

angles = [-1.1071  -0.7854         0    0.7854    1.1071]

Computing inverse tangent of every entry in a matrix

A = [-2 -1 0; 1 2 3];
Y = atan(A)

Expected output:

Y =
   -1.1071   -0.7854         0
    0.7854    1.1071    1.2490

Evaluating atan on a complex number

z = 1 + 2i;
w = atan(z)

Expected output:

w = 1.3390 + 0.4024i

Keeping the result on the GPU with 'like'

proto = gpuArray.zeros(1, 1);
G = gpuArray([-3 -1 0 1 3]);
deviceResult = atan(G, 'like', proto);
result = gather(deviceResult)

Expected output:

result =
   -1.2490   -0.7854         0    0.7854    1.2490

Inspecting character codes via inverse tangent

codes = atan('RUN')

Expected output:

codes =
    1.5586    1.5590    1.5580

Using atan with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how atan changes the result.

Run a small atan example, explain the result, then change one input and compare the output.

FAQ

When should I use atan?

Use atan whenever you need the element-wise inverse tangent of data expressed in radians—common in signal processing, control systems, and geometric computations.

How is atan different from atan2?

atan accepts a single input and returns results in (-π/2, π/2). atan2(y, x) takes two inputs, uses the signs of both arguments to determine the correct quadrant, and returns values in (-π, π].

Does atan support complex numbers?

Yes. Results match MATLAB's analytic continuation of the inverse tangent and may return complex values even for real inputs when the computation requires it.

Can I keep results on the GPU?

Yes. Passing 'like', prototype with a GPU tensor keeps outputs on-device whenever a provider is registered. When the provider lacks unary_atan, RunMat computes on the host and returns host data unless you explicitly request GPU residency via 'like'.

What happens with NaN or Inf inputs?

NaNs propagate, and infinities map to the appropriate asymptotic limits (atan(±Inf) = ±π/2), matching MATLAB's IEEE behavior.

Trigonometry

acos · acosh · asin · asinh · atan2 · atanh · cos · cosd · cosh · deg2rad · rad2deg · sin · sind · sinh · tan · tand · tanh

Elementwise

abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · heaviside · hypot · imag · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times

Reduction

all · any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · eig · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref

Symbolic

digits · int · limit · sym · syms · vpa

Fft

fft · fft2 · fftshift · ifft · ifft2 · ifftshift

Interpolation

interp1 · interp2 · pchip · ppval · spline

Ode

ode15s · ode23 · ode45

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how atan is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.