Effacer les filtres
Effacer les filtres

I am unsure of how I am getting this error

1 vue (au cours des 30 derniers jours)
Cameron Paterson
Cameron Paterson le 27 Oct 2021
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 commentaire
Stephen23
Stephen23 le 27 Oct 2021
Modifié(e) : Stephen23 le 27 Oct 2021
"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:

Connectez-vous pour commenter.

Réponses (1)

David Hill
David Hill le 27 Oct 2021
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

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by