how do I right x^2 in MATLAB

2,740 ビュー (過去 30 日間)
Alex Walton
Alex Walton 2020 年 11 月 23 日
コメント済み: Udhayaraj 2023 年 9 月 23 日
i trying to do some equetion and i come up with an erro message every time i right it out
  1 件のコメント
Udhayaraj
Udhayaraj 2023 年 9 月 23 日
9e^-j(2pi/3) how to command in matlab for cartesian to polar form

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

採用された回答

John D'Errico
John D'Errico 2020 年 11 月 23 日
編集済み: John D'Errico 2020 年 11 月 23 日
Is x a scalar? If so, then you write it as x^2.
Is x a vector? Then, assuming you want to perform an element-wise squaring, you use x.^2.
If you are asking this question, you REALLY need to be reading the getting started tutorials - the Onramp tutorials are a good place to start. There are also multiple MATLAB tutoring sessions on Youtube to watch.
Finally, when you get an error. then show what you did. Show the COMPLETE error message, thus everything in red. Otherwise we need to make wild guesses as to what you did wrong.
  14 件のコメント
Steven Lord
Steven Lord 2020 年 11 月 24 日
John and Rik both suggested that you work through the MATLAB Onramp tutorial and I agree with that suggestion. It is about a two hour long free course with videos and hands-on exercises that are automatically scored (so you get feedback about whether your answer is correct right away) and is designed to teach you the basics of working with MATLAB. I suspect after taking sections 4 and 6 you will understand the difference between the ^ and .^ operators and be able to answer your question.
Alex Walton
Alex Walton 2020 年 11 月 24 日
ok

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2020 年 11 月 23 日
To raise a square matrix to a power use the ^ operator.
To raise each element of an array (the array need not be square or even 2-dimensional) to a power use the .^ operator.
A = [1 2; 3 4]
A = 2×2
1 2 3 4
S1 = A^2
S1 = 2×2
7 10 15 22
S2 = A.^2
S2 = 2×2
1 4 9 16
If your matrix is not square (for example, if it is a row vector) then .^ will work but ^ will not.
thisWillWork = (1:5).^2
thisWillWork = 1×5
1 4 9 16 25
thisWillNOTWork = (1:5)^2
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 '.^'.
  4 件のコメント
Alex Walton
Alex Walton 2020 年 11 月 23 日
you seam more helpfull... my e male is alex-walton3@sky.com
Image Analyst
Image Analyst 2020 年 11 月 24 日
Alex, why won't you ask questions here so all of can benefit from the discussion (like Steven specifically said)? Most volunteers here don't like offering free, private consulting via email when the Mathworks went to all this trouble to set up this nice forum for everyone's benefit. Besides, other people are helpful too. We volunteers range anywhere from people who simply give you the answer outright, to those like John who try to guide you to the answer so that you learn it more deeply than just being handed an answer. Even though John and Steve's approach may not be the fastest today, if you learn MATLAB, you will be faster in the future and won't have to ask. Indeed, hopefully you'll be the expert one day and be helping others here.

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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by