rdivide — Divide arrays element by element with compatible singleton expansion.
rdivide(A, B) and A ./ B divide each element of A by the corresponding element of B. The implementation covers floating-point, complex, fixed-width integer, logical, character, symbolic, and provider-resident operands under their documented class rules.
Syntax
C = rdivide(A, B)
C = rdivide(A, B, "like", prototype)Inputs
A- Type
Any- Required
- Yes
- Description
- First numeric, logical, character, symbolic, sparse, or provider-resident operand.
B- Type
Any- Required
- Yes
- Description
- Second operand with a size compatible for implicit expansion.
like- Type
StringScalar- Required
- Yes
- Description
- Literal `like` selector for the RunMat output-prototype extension.
prototype- Type
LikePrototype- Required
- Yes
- Description
- Host, device, real, or complex output prototype.
Returns
C- Type
NumericArray- Description
- Element-wise result with the broadcasted operand shape.
Errors
RunMat:rdivide:TooManyOutputs- When
- More than one output is requested.
- Message
rdivide: too many output arguments
RunMat:rdivide:InvalidArgument- When
- Optional arguments are malformed or unsupported.
- Message
rdivide: invalid argument
RunMat:rdivide:InvalidInput- When
- Operands or prototypes cannot be converted into supported numeric or symbolic forms.
- Message
rdivide: invalid input
Operands and expansion
Equal dimensions align directly. A singleton dimension expands to the corresponding extent of the other operand. Incompatible non-singleton dimensions produce a size-mismatch error. If a compatible output dimension is zero, the result retains the broadcasted empty shape.
Logical inputs contribute zero or one, and character arrays contribute Unicode code points. String arrays and other nonnumeric containers are rejected. Mixed real and complex inputs return a complex quotient.
Classes and numerical behavior
Double floating-point inputs produce double output. If either floating-point input is single, the result uses single or complex-single storage. Floating-point zero divisors follow IEEE-754 signed-infinity and NaN behavior; complex operands use the complex quotient.
Matching fixed-width integer classes preserve that class. One integer operand may instead be paired with scalar double. Integer quotients round to nearest with half ties away from zero and saturate at the destination class bounds. Wide integer and scalar-double forms use the exact compatibility path rather than first rounding the integer through binary64.
A sparse numerator divided by a nonzero, non-NaN real scalar or a finite nonzero complex scalar keeps CSC storage, applying the numeric-class rules above and removing exact-zero stored results. Zero and NaN divisors require a full result because implicit zeros become NaN; other sparse combinations use a bounded full-result path. Explicit GPU residency still requires a representable provider output.
Provider execution and fusion
A common provider can execute matching resident pairs, real scalar forms, and supported singleton expansion. Every returned handle is checked for provider owner, device, storage kind, class, precision, shape, and non-aliasing before it is accepted.
When a provider cannot satisfy the typed operation, RunMat gathers authoritative storage and evaluates the same host contract. Explicit device intent is restored to the owning provider or the call returns an error; automatically placed values may remain on the host. Compatible floating-point expressions can also be fused with adjacent element-wise work.
Output prototype extension
RunMat mode accepts rdivide(A, B, 'like', prototype). A host prototype requests host output, a provider-resident prototype requests output on that provider, and a complex prototype promotes a real quotient to complex storage. MATLAB compatibility mode rejects this extension before execution.
Examples
Divide matrices element by element
A = [8 12 18; 2 10 18];
B = [2 3 6; 2 5 9];
Q = rdivide(A, B)Expected output:
Q = [4 4 3; 1 2 2]Divide an array by a scalar
A = [9 1 7; 3 10 18; 16 13 4];
Q = rdivide(A, 2)Expected output:
Q = [4.5 0.5 3.5; 1.5 5 9; 8 6.5 2]Expand a column and row
col = (1:3)';
row = [10 20 30];
Q = rdivide(col, row)Expected output:
Q = [0.1 0.05 1/30; 0.2 0.1 1/15; 0.3 0.15 0.1]Divide complex values
z1 = [1+2i, 3-4i];
z2 = [2-1i, -1+1i];
Q = rdivide(z1, z2)Expected output:
Q = [1i -3.5+0.5i]Divide character code points
Q = rdivide('ABC', 2)Expected output:
Q = [32.5 33 33.5]Divide provider-resident arrays
A = gpuArray(single([10 20 30]));
B = gpuArray(single([2 5 10]));
Q = rdivide(A, B);
R = gather(Q)Expected output:
R = single([5 4 3])Request a provider-resident quotient
prototype = gpuArray(single(0));
Q = rdivide(single([1 2 3]), single([2 4 6]), 'like', prototype);
R = gather(Q)Expected output:
R = single([0.5 0.5 0.5])Using rdivide with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how rdivide changes the result.
Run a small rdivide example, explain the result, then change one input and compare the output.
FAQ
Does rdivide support implicit expansion?⌄
Yes. Singleton dimensions expand automatically. Incompatible non-singleton dimensions produce a size-mismatch error.
What numeric class does rdivide return?⌄
Floating-point output is double unless single data participates. Complex inputs produce the corresponding complex floating class. Supported integer forms preserve their integer class; logical and character inputs enter floating-point arithmetic.
How does division by zero behave?⌄
Floating-point division follows IEEE-754: nonzero finite values divided by zero produce signed infinity, and zero divided by zero produces NaN. Complex division uses the complex quotient.
Can a provider-resident array be divided by a host scalar?⌄
Yes for supported real scalar forms. RunMat uses the provider's scalar operation or an exact typed scalar upload when the contract permits it.
What happens when provider execution is unavailable?⌄
RunMat gathers through the owning provider and evaluates the host contract. Explicit device intent must be restored; automatically placed values may remain on the host.
How can I request provider-resident output?⌄
In RunMat mode, pass 'like' and a provider-resident prototype. The runtime either returns a validated result on that provider or reports that the request cannot be preserved.
How are empty arrays handled?⌄
Compatible empty dimensions propagate into the broadcasted output shape, and the result contains no elements.
Are fixed-width integers supported?⌄
Yes. Matching integer classes, or one integer operand with scalar double, preserve the integer class and use nearest ties-away rounding with saturation.
Can real and complex operands be mixed?⌄
Yes. The result is complex, with the same singleton-expansion rules as real division.
Are string arrays accepted?⌄
No. String arrays are not numeric operands for rdivide and produce an input error.
Related Math functions
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 · 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
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
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 rdivide is executed, line by line, in Rust.
- View the source for rdivide 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.