I am unsure of how I am getting this error

1 回表示 (過去 30 日間)
Cameron Paterson
Cameron Paterson 2021 年 10 月 27 日
回答済み: David Hill 2021 年 10 月 27 日
r=linspace(0.001,1,1000);
s=0.75.*((r.^3)/(exp(1)^(.75.*r)));
subplot(2,2,1)
plot(r,s)
xlabel('x')
ylabel('y(x)')
axis([min(r) max(r) min(s) max(s)])
grid on
subplot(2,2,2)
semilogy(r,s)
xlabel('x')
ylabel('y(x)')
axis([min(r) max(r) min(s) max(s)])
grid on
subplot(2,2,3)
semilogx(r,s)
xlabel('x')
ylabel('y(x)')
axis([min(r) max(r) min(s) max(s)])
grid on
subplot(2,2,4)
loglog(r,s)
xlabel('x')
ylabel('y(x)')
axis([min(r) max(r) min(s) max(s)])
grid on
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 '.^'.
Error in HW8P3 (line 2)
s=0.75.*((r.^3)/(exp(1)^(.75.*r)));
  1 件のコメント
Stephen23
Stephen23 2021 年 10 月 27 日
編集済み: Stephen23 2021 年 10 月 27 日
"I am unsure of how I am getting this error"
Did you read the last part of the error message?: To perform elementwise matrix powers, use '.^'.
You probably need to use array operations, not matrix operations:

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

回答 (1 件)

David Hill
David Hill 2021 年 10 月 27 日
r=linspace(0.001,1,1000);
s=0.75*((r.^3)./(exp(1).^(.75*r)));%error is here (multiplying by scalar does not need .*, but you need elementwise operations for matrix operations is needed)
subplot(2,2,1)
plot(r,s)
xlabel('x')
ylabel('y(x)')
axis([min(r) max(r) min(s) max(s)])
grid on
subplot(2,2,2)
semilogy(r,s)
xlabel('x')
ylabel('y(x)')
axis([min(r) max(r) min(s) max(s)])
grid on
subplot(2,2,3)
semilogx(r,s)
xlabel('x')
ylabel('y(x)')
axis([min(r) max(r) min(s) max(s)])
grid on
subplot(2,2,4)
loglog(r,s)
xlabel('x')
ylabel('y(x)')
axis([min(r) max(r) min(s) max(s)])
grid on

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by