MATLAB Answers

Why can't I solve this, it's simple. (Incorrect dimensions.... use .^) (I did then it says Invalid Operator.......)

4 ビュー (過去 30 日間)
adr58_1
adr58_1 2019 年 10 月 9 日
回答済み: Steven Lord 2019 年 10 月 9 日
>> [x,y]=meshgrid(1:1:exp(5), -3:0.01:3)
>> z=((x+1)^y)-(x^y)
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a
scalar. To perform elementwise matrix powers, use '.^'.
>> z=((x+1)^.y)-(x^y)
z=((x+1)^.y)-(x^y)
Error: Invalid use of operator.

  0 件のコメント

Sign in to comment.

採用された回答

Daniel M
Daniel M 2019 年 10 月 9 日
編集済み: Daniel M 2019 年 10 月 9 日
This works fine:
z = ((x+1).^y)-(x.^y);
You should read a bit on the difference between array and matrix operations.

  1 件のコメント

adr58_1
adr58_1 2019 年 10 月 9 日
Thanks a lot, sorry newbie over here hehe

Sign in to comment.

その他の回答 (1 件)

Steven Lord
Steven Lord 2019 年 10 月 9 日
The operator .^ (period followed by a caret) performs elementwise matrix power.
There is no operator ^. (caret followed by a period) in MATLAB. That can still be a valid sequence of symbols (the first example below shows one such use) but it is not valid in the context in which you're using it (the first part of the second and third examples.) The second part of the second and third examples show how you would perform those computations using the .^ operator.
2^.5 % 2 to the 1/2 power or sqrt(2)
x = 0.5;
2^.x % error
2.^x % sqrt(2)
y = 5;
2^.y % Nope
2.^y % 2^5 = 32

  0 件のコメント

Sign in to comment.

製品


リリース

R2019b

Translated by