atan — Compute elementwise principal inverse tangent in radians with optional RunMat output templating.
atan preserves floating precision and shape, keeps real input real, supports principal complex results, and retains supported provider placement.
Syntax
Y = atan(X)
Y = atan(X, "like", P)Inputs
X- Type
Any- Required
- Yes
- Description
- Single or double real/complex input; integer, logical, and character forms are RunMat-only extensions.
like- Type
StringScalar- Required
- Yes
- Default
"like"- Description
- RunMat-only output-template selector.
P- Type
LikePrototype- Required
- Yes
- Description
- RunMat-only prototype selecting host/provider residency and real/complex representation.
Returns
Y- Type
NumericArray- Description
- Elementwise principal inverse-tangent result in radians.
Errors
RunMat:atan:InvalidInput- When
- Input is not a supported numeric, logical, or character value.
- Message
atan: invalid input
RunMat:atan:InvalidOption- When
- Optional arguments after X are malformed or unsupported.
- Message
atan: invalid option
RunMat:atan:ArgCount- When
- The call supplies an unsupported number of inputs.
- Message
atan: too many input arguments
Behavior
atan(X) computes the principal inverse tangent of each element in radians. Real input always returns real output in the interval [-pi/2, pi/2]; complex floating input follows the principal analytic continuation.
Real and complex single input returns single-precision storage, while real and complex double input returns double precision. Scalar, vector, matrix, empty, and N-D shape is preserved. NaN propagates and real positive or negative infinity approaches positive or negative pi/2.
RunMat extensions
RunMat mode accepts all eight real fixed-width integer classes, logical arrays, and character arrays. These forms cross an explicit binary64 computation boundary and return real double output with the input shape. Character elements are interpreted as Unicode scalar values.
RunMat mode also accepts atan(X, "like", P). A real or complex prototype selects the corresponding result representation, with host placement for a host prototype or placement on the concrete owner of a provider-resident prototype. A complex prototype promotes a real result to complex storage with zero imaginary components without changing the input's floating precision. A real prototype cannot represent a complex result. Strings, sparse arrays, typed complex integers, direct table/timetable overloads, and tall containers are rejected.
GPU execution and fusion
Supported real floating input can use the owning provider's unary inverse-tangent operation. An unsupported hook gathers through the input owner, computes on the host, and restores the result to that owner and device. Integer and logical resident extensions use the same owner-preserving fallback.
Real inverse tangent has no value-dependent complex promotion, so its real floating expression can participate in elementwise fusion. Complex input and output-template conversion remain ordinary runtime boundaries rather than using that real-only fused expression.
Examples
Compute inverse tangent of a scalar
y = atan(1)Expected output:
y = 0.7854Apply inverse tangent elementwise to a vector
x = linspace(-2, 2, 5);
angles = atan(x)Expected output:
angles = [-1.1071 -0.7854 0 0.7854 1.1071]Apply inverse tangent elementwise to 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.2490Evaluate a complex value on the principal branch
z = 1 + 2i;
w = atan(z)Expected output:
w = 1.33897 + 0.40236iSelect provider placement with a prototype
prototype = gpuArray(zeros(1, 1));
G = gpuArray([-3 -1 0 1 3]);
deviceResult = atan(G, "like", prototype);
result = gather(deviceResult)Expected output:
result = [-1.2490 -0.7854 0 0.7854 1.2490]Request complex single output on the prototype owner
x = single([0 0.5]);
prototype = gpuArray(complex(single(0), single(1)));
deviceResult = atan(x, "like", prototype);
result = gather(deviceResult);Evaluate character code points in RunMat mode
codes = atan('RUN')Expected output:
codes is a 1-by-3 double row vectorUsing 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 for elementwise inverse tangent when one coordinate or ratio is available. Use atan2(y, x) when the signs of two coordinates must determine the quadrant.
How is atan different from atan2?⌄
atan takes one input and real results lie in [-pi/2, pi/2]. atan2 takes y and x, resolves the quadrant from both signs, and returns a wider angular range.
Does atan support complex numbers?⌄
Yes. Complex single and double input follow the principal analytic continuation and preserve their floating precision.
Can atan results remain provider-resident?⌄
Yes. Supported real floating input uses the provider hook, while unsupported resident forms gather and restore through the same owner. RunMat's "like" form can independently select real provider placement.
What happens with NaN or infinity?⌄
Real NaN propagates. Real positive and negative infinity return positive and negative pi/2, respectively.
Does atan fuse with neighboring operations?⌄
The real floating one-input form can participate in elementwise fusion because real inverse tangent does not require value-dependent complex promotion. Other forms remain runtime boundaries.
Related Math functions
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan2 · atan2d · atand · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Elementwise
abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
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
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
Source you can read
Every RunMat function's source is public. 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 a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.