Filter löschen
Filter löschen

how to vectorize a parameterized surface

1 Ansicht (letzte 30 Tage)
Ana Egatz-Gomez
Ana Egatz-Gomez am 10 Dez. 2021
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')

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 10 Dez. 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')

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by