Language reference
Operators
Verified arithmetic, element-wise, comparison, logical, assignment, and range syntax.
Operator groups
~= is inequality; != is not accepted. && and || short-circuit. Logical negation is !; standalone ~ is only an output discard marker, not unary negation.
| Group | Tokens |
|---|---|
| Arithmetic | + - * / ^ |
| Element-wise | .* ./ .^ |
| Transpose | .' ' |
| Comparison | == ~= < <= > >= |
| Logical | ! && || |
| Assignment and range | = : |
| Output discard | ~ |
| Syntax | . ( ) [ ] { } , ; % %% |
EN: Matrix left division
A\B and mldivide(A,B) accept only dense REAL MATRIX A m-by-n and B m-by-p, returning one MATRIX X n-by-p, even for 1-by-1. No implicit Number, logical, complex or string conversion; scalar backslash and .\ are unsupported. Existing / and ./ are unchanged. Shape alone dispatches square A to exactly solve(A,B), rectangular A to exactly default lsqminnorm(A,B); see Linear algebra for protected LU, SVD minimum norm and errors.
The binary operator evaluates left then right, each once, and bypasses overloaded session functions. The named alias follows ordinary function dispatch and can be shadowed; @mldivide is supported. Multiplicative * / .* ./ and \ have equal precedence and associate left-to-right: A\B*C=(A\B)*C and A*B\C=(A*B)\C. They bind below power/postfix transpose (and prefix signs), above addition, colon and comparisons. Backslashes inside strings and comments remain literal: no C-style escapes. Use sun run: neither operator nor alias has native LLVM lowering; no C ABI change.
A = [2,0;0,4];
B = [2,4;8,12];
C = [1,2;0,1];
X = A\B;
disp(all(size(X)==[2,2]) && all(abs(X-solve(A,B))<1e-12));
disp(all(abs(A\B*C-(A\B)*C)<1e-12));
disp(all(abs(A*B\C-(A*B)\C)<1e-12));
disp(all(abs(A\B.'-solve(A,B.'))<1e-12));
disp(all(abs(A\B+ones(2)-(X+ones(2)))<1e-12));PT: Divisao matricial esquerda
A\B e mldivide(A,B) exigem MATRIZ REAL DENSA A m por n e B m por p; retornam uma MATRIZ X n por p, inclusive 1 por 1. Sem conversao implicita de Number, logicos, complexos ou texto; backslash escalar e .\ nao sao suportados. / e ./ existentes permanecem iguais. Somente a forma despacha A quadrada para exatamente solve(A,B), retangular para exatamente lsqminnorm(A,B) padrao.
O operador binario avalia esquerda e depois direita, uma vez cada, sem chamar funcoes de sessao sobrecarregadas. O alias nomeado segue despacho normal e pode ser sombreado; aceita @mldivide. * / .* ./ e \ tem a mesma precedencia e associam da esquerda para direita: A\B*C=(A\B)*C e A*B\C=(A*B)\C. Ficam abaixo de potencia/transposta e sinais prefixos, acima de adicao, dois-pontos e comparacoes. Backslashes em strings e comentarios sao literais, sem escapes C. Operador e alias exigem sun run, sem LLVM nativo nem alteracao da ABI C.
X = [2]\[6];
Y = mldivide([2],[6]);
left = @mldivide;
Z = left([1,1],[2]);
disp(all(size(X)==[1,1]) && all(size(Y)==[1,1]) && abs(X(1)-3)<1e-12 && abs(Y(1)-3)<1e-12);
disp(all(size(Z)==[2,1]) && all(abs(Z-[1;1])<1e-12));
% A\B stays literal here, as in this string:
text = 'A\B';
matched = false;
switch text
case 'A\B'
matched = true;
end
disp(matched);Element-wise power and transpose
.^ supports scalar expansion and compatible 2D broadcasting for real, logical and complex values. A negative real base with a finite fractional exponent promotes the result to complex. ^ remains scalar-only with real f64 domain behavior; it is not matrix power.
A.' swaps axes without conjugating; A' swaps axes and conjugates complex components. Both preserve real, logical and complex types, accept scalars and empty arrays, and return independent arrays. transpose(A) is the nonconjugating array-only function.
A = [1+i, 2-i; 3, 4*i];
plain = A.';
conjugated = A';
powers = [-1, 4] .^ 0.5;Precedence and migration
Power and postfix transpose share precedence, associate left-to-right, and bind above prefix signs. Multiplication/division follow, then addition/subtraction, colon, comparisons, && and ||.
This changes older scripts: -2^2 now means -(2^2), giving -4; 2^3^2 means (2^3)^2, giving 64. A.^2' means (A.^2)'. Parenthesize signed bases and chained exponents deliberately.
disp(-2^2); % -4
disp((-2)^2); % 4
disp(2^3^2); % 64
disp(2^(3^2)); % 512These operators are interpreter features, including pure expressions in parfor. The native backend does not lower power or postfix transpose.