what is the different between B^2 and B.^2

168 ビュー (過去 30 日間)
melissa tan
melissa tan 2018 年 9 月 2 日
回答済み: Minyoung Hong 2022 年 6 月 8 日
what is the different between B^2 and B.^2?
  1 件のコメント
Paolo Volpe
Paolo Volpe 2021 年 12 月 19 日
thank you

サインインしてコメントする。

採用された回答

Stephen23
Stephen23 2018 年 9 月 3 日
編集済み: Stephen23 2018 年 9 月 4 日
These are certainly NOT the same operations, and the sizes of the matrices does not determine which operations to use. You need to pick the operation, based on what you are trying to calculate.
From their documentation pages:
  • .^ power gives the "element-wise power", so that C = A.^B raises each element of A to the corresponding power in B.
  • ^ mpower gives the "matrix power", so that C = A^B computes A to the B power. For your example, with a scalar B, this is equivalent to A*A.
Lets try them: first we can look at the power operation:
>> A = [1,2;3,4];
>> B = 2;
>> A.^2 % element-wise power
ans =
1 4
9 16
You can see that each element of the output is simply the element of A to the power 2:
>> A(1,1)*A(1,1)
ans = 1
>> A(1,2)*A(1,2)
ans = 4
>> A(2,1)*A(2,1)
ans = 9
>> A(2,2)*A(2,2)
ans = 16
What about A.^3? I am sure that you can spot the pattern:
>> A.^3
ans =
1 8
27 64
>> A(2,2)*A(2,2)*A(2,2)
ans = 64
Now lets look at the mpower operation:
>> A^2
ans =
7 10
15 22
And you will see that this is simply equivalent to:
>> A*A
ans =
7 10
15 22
Now try A^3 to see the pattern:
>> A^3
ans =
37 54
81 118
>> A*A*A
ans =
37 54
81 118
Read about the differences between matrix (linear algebra) and array (element-wise) operations here:

その他の回答 (1 件)

Minyoung Hong
Minyoung Hong 2022 年 6 月 8 日
thanks!

カテゴリ

Help Center および File ExchangeArithmetic Operations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by