atan — Element-wise inverse tangent in MATLAB and RunMat.
Y = atan(X) computes the inverse tangent (in radians) of each element in X. The additional atan(X, "like", P) output-template form is a RunMat-only extension.
Syntax
Y = atan(X)
Y = atan(X, "like", P)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
X | Any | Yes | — | Single/double real or complex input; integer, logical, and character forms are RunMat-only extensions. |
like | StringScalar | Yes | "like" | RunMat-only output template selector keyword. |
P | LikePrototype | Yes | — | RunMat-only prototype determining host/gpu residency and real/complex output class. |
Returns
| Name | Type | Description |
|---|---|---|
Y | Any | Element-wise inverse tangent result. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:atan:InvalidInput | Input cannot be interpreted as supported numeric/char/complex data. | atan: invalid input |
RunMat:atan:InvalidOption | Optional arguments after X are malformed or unsupported. | atan: invalid option |
RunMat:atan:ArgCount | Too many input arguments were supplied. | atan: too many input arguments |
RunMat:atan:LikePrototype | The "like" prototype or requested output class is unsupported. | atan: invalid "like" prototype |
RunMat:atan:GpuUnavailable | GPU output was requested via "like" but no active provider is available. | atan: GPU provider unavailable |
RunMat:atan:Internal | Internal gather/conversion/allocation/provider flow failed. | atan: internal error |
RunMat:atan:TooManyOutputs | More than one output is requested. | atan: too many output arguments |
How atan works
- Documented single and complex-single inputs preserve native single storage; double and complex-double inputs preserve double storage.
- The documented table and timetable overloads are not yet implemented in RunMat.
- Typed-integer, logical, and character inputs are RunMat-only extensions. They enter an explicit double computation boundary and preserve input 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, computes the result with the reference implementation, and restores it to the input handle's owning provider.
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
When a provider exposes unary_atan, the runtime keeps data on the GPU. If the hook is missing, RunMat gathers, computes, and restores the result to the input handle's owning provider. RunMat mode can independently override placement with the gated 'like' output-template extension.
Examples
Arctangent of a scalar
y = atan(1)Expected output:
y = 0.7854Element-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.2490Evaluating atan on a complex number
z = 1 + 2i;
w = atan(z)Expected output:
w = 1.3390 + 0.4024iMatching output storage to a prototype
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.2490Computing arctangent values from character codes
codes = atan('RUN')Expected output:
codes =
1.5586 1.5590 1.5580Using 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. Complex floating inputs follow the principal analytic continuation; real floating inputs remain real.
Can I keep results on the GPU?⌄
Documented resident input stays on-device when possible and uses owner-preserving fallback otherwise. RunMat mode additionally offers the 'like' output-template extension for explicit host/GPU placement.
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.
Related Math functions
Trigonometry
acos · acosh · asin · asinh · atan2 · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Elementwise
abs · angle · bsxfun · complex · conj · double · erf · erfcinv · exp · expm1 · factorial · flintmax · gamma · gammaln · heaviside · hypot · idivide · imag · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · swapbytes · times · typecast · uint16 · uint32 · uint8
Reduction
all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Signal
blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Optim
coneprog · fminbnd · fminunc · fsolve · fzero · integral · linprog · lsqcurvefit · lsqnonlin · optimoptions · optimset · quad · secondordercone
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how atan is executed, line by line, in Rust.
- View the source for atan in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.