[bug #48564] Octave does not accept "1 / ND array", "mrdivide (1, ND array)", "mldivide (ND array, 1)"
Nicholas Jankowski <[email protected]>
| Newsgroups | gmane.comp.gnu.octave.bugs |
|---|---|
| Message-ID | <[email protected]> |
Please use the bug tracker to post updates to a bug report. The mailing list is intended as a read-only notification stream. Info posted to this mailing list address won't appear in the tracker database where it is most useful.
Follow-up Comment #13, bug #48564 (group octave):
good question. and now that i look closer it seems no not that simple. I'm
tempted to recategorize this as wtf matlab, but we do still deviate from
published behavior and could fix that.
here's the current matlab help text for supposed intent:
mldivide (mrdivide pretty much the same):
x = A\B solves the system of linear equations A*x = B. The matrices A and B
must have the same number of rows. MATLAB® displays a warning message if A is
badly scaled or nearly singular, but performs the calculation regardless.
If A is a scalar, then A\B is equivalent to A.\B.
If A is a square n-by-n matrix and B is a matrix with n rows, then x = A\B is
a solution to the equation A*x = B, if it exists.
If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with m
rows, then A\B returns a least-squares solution to the system of equations
A*x= B. x may not be the minimum-norm solution.
For the A=1 case, the first two apply, and it seems to be a desicion tree
precedence issue. is 1 a scalar or a 1x1 square matrix. if B is non-2D, the
scalar case plays out and elementwise operations apply. if B is 2D, it treats
1 as a 1x1 square matrix and tries to do division, which runs into a size
mismatch error for anything with more than 1 column (or rows for the other
one). see below:
matlab 2025a:
>> 1 / [1 2 3]
Error using /
Matrix dimensions must agree.
>> 1 / [1 2 3]'
ans =
0 0 0.3333
>> 1/rand(2,2)
Error using /
Matrix dimensions must agree.
>> 1/rand(2,4)
Error using /
Matrix dimensions must agree.
>> 1/rand(4,2)
Error using /
Matrix dimensions must agree.
>> 1/rand(2,4,2)
ans(:,:,1) =
1.5472 1.3251 1.4712 6.1496
1.4097 3.6229 1.5265 8.4035
ans(:,:,2) =
2.0066 2.9378 4.4680 3.9201
1.0419 1.7086 1.3311 1.9765
>> 1/rand(3,3)
Error using /
Matrix dimensions must agree.
>> 1/rand(3,3,3)
ans(:,:,1) =
1.2274 1.0948 3.5907
1.1040 1.5814 1.8285
7.8748 10.2522 1.0444
ans(:,:,2) =
1.0364 1.0447 7.0479
6.3447 2.0603 2.3710
1.0303 1.2496 1.0920
ans(:,:,3) =
1.2623 28.0020 1.4733
1.0422 1.1777 1.3197
1.5250 1.0707 1.3457
i'm probably going to file a matlab bug report on that one. based on their
help text it seems like A = 1 should hit the scalar rules for all cases.
For now i'd say if we were to change anythnig it would be to follow the
published behavior (scalar/X _should_ do scalar./X for any X).
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?48564>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc
(application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCaZYRewAKCRCqLAuaBUf3 TpkkAP4rs7H0P0j3ScVu+7+YssB1I8nc72s34pE/TeGmj6PEqgEA5uVFghAxre3W blV9LOhqRtz6rwE4i65tnizaKuQ06Ak= =3FRz -----END PGP SIGNATURE-----