필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
August Lindberg
August Lindberg 2021년 11월 25일
댓글: August Lindberg 2021년 11월 25일
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!

채택된 답변

DGM
DGM 2021년 11월 25일
편집: DGM 2021년 11월 25일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by