フィルターのクリア

how to vectorize a parameterized surface

1 回表示 (過去 30 日間)
Ana Egatz-Gomez
Ana Egatz-Gomez 2021 年 12 月 10 日
コメント済み: Ana Egatz-Gomez 2023 年 5 月 2 日
The code below makes a parameterized 3D surface. It looks like a circle intersected by a paraboloid of revolution. The figure looks fine, but I am getting warnings:
"Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments....."
How can I improve the code to avoid the warnings?
Thanks in advance.
funx = @(r,th) r * cos(th) ;
funy = @(r,th) r * sin(th);
funz = @(r,th) 500-real(sqrt((4*125.*(r .* sin(th)+125))-(r .* cos(th)).^2));
parab3D=fsurf(funx,funy,funz,[0 500 0 2*pi],'MeshDensity',500,'EdgeColor','none') ;
hold on;
daspect([1 1 1]);
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')

採用された回答

Voss
Voss 2021 年 12 月 10 日
The warning is because funx and funy are using the matrix operation * rather than the element-wise operation .* (funz is ok - already vectorized, hence no warning for that one). So do it this way instead:
funx = @(r,th) r .* cos(th);
funy = @(r,th) r .* sin(th);
  1 件のコメント
Ana Egatz-Gomez
Ana Egatz-Gomez 2021 年 12 月 10 日
Thank you very much Benjamin. I didn't see those ones!

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 12 月 10 日
funx = @(r,th) r .* cos(th) ;
funy = @(r,th) r .* sin(th);
funz = @(r,th) 500-real(sqrt((4*125.*(r .* sin(th)+125))-(r .* cos(th)).^2));
parab3D=fsurf(funx,funy,funz,[0 500 0 2*pi],'MeshDensity',500,'EdgeColor','none') ;
hold on;
daspect([1 1 1]);
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
  1 件のコメント
Ana Egatz-Gomez
Ana Egatz-Gomez 2023 年 5 月 2 日
Thank you Walter

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by