Borrar filtros
Borrar filtros

how to vectorize a parameterized surface

1 visualización (últimos 30 días)
Ana Egatz-Gomez
Ana Egatz-Gomez el 10 de Dic. de 2021
Comentada: Ana Egatz-Gomez el 2 de Mayo de 2023
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')

Respuesta aceptada

Voss
Voss el 10 de Dic. de 2021
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 comentario
Ana Egatz-Gomez
Ana Egatz-Gomez el 10 de Dic. de 2021
Thank you very much Benjamin. I didn't see those ones!

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 10 de Dic. de 2021
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')

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by