how do I right x^2 in MATLAB
Show older comments
i trying to do some equetion and i come up with an erro message every time i right it out
1 Comment
Abhishek
on 18 Jul 2024
Nice!!!!
Accepted Answer
More Answers (1)
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]
S1 = A^2
S2 = A.^2
If your matrix is not square (for example, if it is a row vector) then .^ will work but ^ will not.
thisWillWork = (1:5).^2
thisWillNOTWork = (1:5)^2
4 Comments
Alex Walton
on 23 Nov 2020
Steven Lord
on 23 Nov 2020
If you're asking if you can email me directly, I'm on vacation for the next week or so (only sporadically checking Answers.) Posting your follow-up questions as comments on this post (or as new posts, if they're unrelated to this topic) will let others answer more quickly than I will.
Alex Walton
on 23 Nov 2020
Image Analyst
on 24 Nov 2020
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.
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!