I am unsure of how I am getting this error

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by