フィルターのクリア

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 Center および File ExchangeSurface 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