what does "^" and ".^" difference ?

30 ビュー (過去 30 日間)
Muhammad Faqih
Muhammad Faqih 2019 年 9 月 27 日
回答済み: Cam 2019 年 9 月 27 日
surely "^" and ".^" had difference in their using. but what exactly they does?

採用された回答

Walter Roberson
Walter Roberson 2019 年 9 月 27 日
>> [1 2;3 4]^2
ans =
7 10
15 22
>> [1 2;3 4].^2
ans =
1 4
9 16
>> [1 2; 3 4]*[1 2; 3 4] %same as ^2
ans =
7 10
15 22
>> [1 2; 3 4].*[1 2;3 4] %same as .^2
ans =
1 4
9 16
The formal names of the operations are mpower (^) and power (.^) . ^ is for matrix multiplication repeated, where .^ is for element-by-element multiplication repeatedly.

その他の回答 (1 件)

Cam
Cam 2019 年 9 月 27 日
The dot is a element wise operator, this means that each element is operated on by the element of the same index when you use this. The other "^" will raise any value (scalar, or matrix) to the power of it. A bit difficult to explain in words here is an example:
a = [1 2;3 4]
b = [2 2;2 2]
a.^b = [1 4;9 16]
As you can see it went element by element and applied the operator. 1^2, 2^2; 2^3, 2^4
In contrast if you do:
a = [1 2;3 4]
b = [2 2;2 2]
a^b = %ERROR must be a scalar
a^2 = [1 4;9 16]
The dot is more applicable to other operators like multiplication and division its less used but still often needed as matlab always assumes matricies are being used first.

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by