how to vectorize a parameterized surface

1 次查看(过去 30 天)
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 个)

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 中查找有关 MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by