Effacer les filtres
Effacer les filtres

Plot surface of z=(x^2+y^2)^m for different values of m

4 vues (au cours des 30 derniers jours)
August Lindberg
August Lindberg le 25 Nov 2021
Commenté : August Lindberg le 25 Nov 2021
I have problem plotting the above function for different values of m. I have an example that I follow but I get stuck defining the function Z and thus receive the following error code:
r=linspace(0,1,21);
theta=linspace(0,2*pi,63);
[R,THETA]=meshgrid(r,theta);
X=R.*cos(THETA);
Y=R.*sin(THETA);
>> m=1/3
>> Z=(X.^2+Y.^2)^m;
surf(X,Y,Z) % rita ytan
axis equal
Error using ^ (line 52)
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 '.^'.
What am I doing wrong? Thanks in advance!

Réponse acceptée

DGM
DGM le 25 Nov 2021
Modifié(e) : DGM le 25 Nov 2021
Almost there
r=linspace(0,1,21);
theta=linspace(0,2*pi,63);
[R,THETA]=meshgrid(r,theta);
X=R.*cos(THETA);
Y=R.*sin(THETA);
m=1/3;
%Z=(X.^2+Y.^2).^m; % elementwise power too
Z = R.^(2*m); % this is equivalent
surf(X,Y,Z) % rita ytan
axis equal

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by