필터 지우기
필터 지우기

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 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