You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MATLAB will happily let you add a scalar to a vector, or even a scalar to a matrix. If a is a matrix or vector and b is a scalar value, then a + b will return a copy of a with b added to every element, and likewise b + a, instead of doing the sensible thing and raising a type error.
Of course, we can generalize this a bit for BS. If a is an array, b is a non-array type, and op is an operator -- literally any operator in the whole language -- such that a op b would otherwise be invalid, then instead a op b returns an array with the same length of a such that for each element a_i in the original array a, the returned array has a_i op b in the same position. Likewise for b op a returning an array of b op a_i for each a_i in a.
This also implies that if a is an array of arrays, b is recursively applied to every array in a to produce the output array.
The text was updated successfully, but these errors were encountered:
MATLAB will happily let you add a scalar to a vector, or even a scalar to a matrix. If
a
is a matrix or vector andb
is a scalar value, thena + b
will return a copy ofa
withb
added to every element, and likewiseb + a
, instead of doing the sensible thing and raising a type error.Of course, we can generalize this a bit for BS. If
a
is an array,b
is a non-array type, andop
is an operator -- literally any operator in the whole language -- such thata op b
would otherwise be invalid, then insteada op b
returns an array with the same length ofa
such that for each elementa_i
in the original arraya
, the returned array hasa_i op b
in the same position. Likewise forb op a
returning an array ofb op a_i
for eacha_i
ina
.This also implies that if
a
is an array of arrays,b
is recursively applied to every array ina
to produce the output array.The text was updated successfully, but these errors were encountered: