cosd — Compute elementwise cosine for degree-valued angles with exact canonical results.
cosd evaluates degree-scaled cosine and handles canonical real angles before the general floating calculation.
Syntax
Y = cosd(X)Inputs
X- Type
Any- Required
- Yes
- Description
- Single or double real/complex input; integer, logical, and character forms are RunMat-only extensions.
Returns
Y- Type
NumericArray- Description
- Elementwise cosine result for degree-valued input.
Errors
RunMat:cosd:InvalidInput- When
- Input is not a supported numeric, logical, or character value.
- Message
cosd: invalid input
RunMat:cosd:Internal- When
- Internal gather, conversion, allocation, or provider restoration failed.
- Message
cosd: internal error
RunMat:cosd:TooManyOutputs- When
- More than one output is requested.
- Message
cosd: too many output arguments
Behavior
cosd(X) evaluates cosine with X measured in degrees. It returns exact zero at odd multiples of 90, exact positive or negative one at multiples of 180, and exact positive or negative one-half at angles congruent to 60 or 120 degrees with the corresponding sign. Other finite values use the degree-scaled analytic function; non-finite real input returns NaN.
The operation is elementwise and preserves scalar, vector, matrix, empty, and N-D shape. Real and complex single input returns single; real and complex double input returns double. Complex input uses the analytic continuation after scaling by pi/180; canonical snapping applies only to real input.
RunMat extensions
RunMat mode accepts all eight real fixed-width integer classes when each value is exactly representable at the binary64 trigonometric boundary. The result is double; aligned values above flintmax remain accepted when conversion is exact, while values that would lose information are rejected.
Logical and character arrays are separately gated RunMat extensions and return double. Character input is evaluated from exact Unicode scalar values. Strings, sparse arrays, typed complex integers, tables, timetables, and tall containers are rejected. Execution-owned distributed arrays use the catalog's unary mapping policy.
Execution placement
Provider-resident input gathers through its owner for canonical host evaluation, then the result is uploaded to that same owner. Fusion is disabled because lowering to cos(X*pi/180) would lose exact canonical results.
Examples
Evaluate a canonical angle
y = cosd(60)Expected output:
y = 0.5Return exact zeros at odd quarter-turns
y = cosd([90 270])Expected output:
y = [0 0]Evaluate common degree angles
angles = [0 30 45 60 90];
y = cosd(angles)Expected output:
y = [1 0.8660 0.7071 0.5 0]Evaluate character code points in RunMat mode
y = cosd('AZ')Expected output:
y contains cosd(65) and cosd(90)Restore canonical results to the input provider
G = gpuArray([0 60 90]);
y = cosd(G);
hostY = gather(y)Expected output:
hostY = [1 0.5 0]Using cosd with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how cosd changes the result.
Run a small cosd example, explain the result, then change one input and compare the output.
FAQ
Why does cosd(90) return exactly zero?⌄
RunMat reduces real angles modulo 360 and handles canonical cases before the floating cosine calculation, avoiding noise from an approximate value of pi.
Is cosd(X) equivalent to cos(X*pi/180)?⌄
They are mathematically equivalent, but the direct expression can contain rounding noise at canonical angles. cosd returns the defined exact values there.
Does cosd support arrays?⌄
Yes. It operates elementwise and preserves the input shape.
Related Math functions
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · atanh · cos · 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 cosd is executed, line by line, in Rust.
- View the source for cosd 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.