필터 지우기
필터 지우기

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')

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by