Borrar filtros
Borrar filtros

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

4 visualizaciones (últimos 30 días)
August Lindberg
August Lindberg el 25 de Nov. de 2021
Comentada: August Lindberg el 25 de Nov. de 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!

Respuesta aceptada

DGM
DGM el 25 de Nov. de 2021
Editada: DGM el 25 de Nov. de 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

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by