Introduction
Element-wise operations let you do math on each item in two lists or arrays separately, just like doing the same task on each apple in a basket.
C = A .* B C = A ./ B C = A .^ B
A = [1 2 3]; B = [4 5 6]; C = A .* B;
A = [10 20 30]; B = [2 4 5]; C = A ./ B;
A = [2 3 4]; B = [3 2 1]; C = A .^ B;
A = [1 2 3]; B = [4 5 6]; mult = A .* B; div = A ./ B; pow = A .^ B; fprintf('Multiplication result: '); fprintf('%d ', mult); fprintf('\n'); fprintf('Division result: '); fprintf('%.2f ', div); fprintf('\n'); fprintf('Power result: '); fprintf('%d ', pow); fprintf('\n');
.* do when applied between two arrays of the same size?.* in MATLAB.* operator multiplies corresponding elements of two arrays of the same size.* without the dot and follows linear algebra rules, unlike element-wise multiplication..* means element-wise multiply [OK].* with matrix multiplication *.* divides arrays.* raises to powerA and B in MATLAB?./ between arrays./ is matrix right division, .\ is element-wise left division, and // is not valid in MATLAB../ means element-wise division [OK]/ instead of .///A = [2, 4; 6, 8];
B = [1, 2; 3, 4];
C = A .^ B;
.^ raises each element of A to the power of the corresponding element in B..^ to power elements individually [OK].^ with matrix power ^X = [1, 2, 3];
Y = [4, 5];
Z = X .* Y;
X is 1x3 and Y is 1x2, sizes do not match..* [OK]M = [1, 2, 3; 4, 5, 6];
N = [2, 0, 1; 3, 4, 5];
R where each element is the result of M element-wise multiplied by N, then divided element-wise by N plus 1. Which MATLAB expression correctly computes R?.* and element-wise division uses ./..* and ./ with parentheses.*, which is incorrect./, which is invalid here.Pass the test and this pattern moves unknown