Error Using ^ When Typing Power Command

조회 수: 6 (최근 30일)
Duong Nguyen
Duong Nguyen 2018년 1월 17일
댓글: Duong Nguyen 2018년 1월 17일
I want to plot a graph of y versus t with:
>> t = linspace(0,10,20);
>> y = 1/(t*(3/10^(8*8)*10^(3/2))/2 + 1)^(2/3);
But when I finished writing the second line, the error appeared: Error using ^ One argument must be a square matrix and the other must be a scalar. Use POWER (.^) for elementwise power. So how can I solve this problem?
  댓글 수: 1
Stephen23
Stephen23 2018년 1월 17일
Why not do EXACTLY what the error message advises you to do?
Read this to know the difference between ^ and .^:

댓글을 달려면 로그인하십시오.

채택된 답변

Elias Gule
Elias Gule 2018년 1월 17일
Let's say for example you have the vector:
t = 1 : 10;
This is basically a 1-by-10 matrix. So,
t^2
tries to perform the matrix multiplication operation; but t is 1x10, hence the inner dimensions of t*t are not the same. That is why you get an error.
Now if what you actually want is an array of squares of elements of t, then
t.^2
is the what you must use. So you equation should be :
y = 1./(t*(3/10^(8*8)*10^(3/2))/2 + 1).^(2/3);
Note: ./, .* and .^ are element-wise operators.
  댓글 수: 1
Duong Nguyen
Duong Nguyen 2018년 1월 17일
Thank you for your explanation. I have just studied MATLAB for a week so I do not understand it fully. It is a really helpful comment.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by