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

3 views (last 30 days)
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!

Accepted Answer

DGM
DGM on 25 Nov 2021
Edited: DGM on 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

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!