Piecewise over circles 3d

1 visualizzazione (ultimi 30 giorni)
Eli
Eli il 21 Giu 2012
Hey,
How would one go about doing a 3d piecewise plot over circular bases? For example:
If (x^2+y^2 <= pi^2), then z=sin(sqrt(x^2+y^2))/sqrt(x^2+y^2)
If ((x-2pi)^2+y^2 <=pi^2), then z = sin(sqrt((x-2pi)^2+y^2))/sqrt((x-2pi)^2+y^2)
If ((x+2pi)^2+y^2 <=pi^2), then z = sin(sqrt((x+2pi)^2+y^2))/sqrt((x+2pi)^2+y^2)
Else no graph there
(Then plot a 3d graph of this)
Thanks!

Risposte (2)

Walter Roberson
Walter Roberson il 21 Giu 2012
xrange = -10 : 0.01 : 10; %use appropriate range
yrange = -10 : 0.01 : 10; %use appropriate range
[x, y] = ndgrid(xrange, yrange);
z = nan(size(x));
idx = x.^2+y.^2 <= pi^2;
z(idx) = sin(sqrt(x(idx).^2+y(idx).^2))/sqrt(x(idx).^2+y(idx).^2);
idx = (x-2*pi).^2+y.^2 <=pi^2;
z(idx) = sin(sqrt((x(idx)-2*pi).^2+y(idx).^2))/sqrt((x(idx)-2*pi).^2+y(idx).^2);
idx = (x+2*pi).^2+y.^2 <=pi^2;
z(idx) = sin(sqrt((x(idx)+2*pi).^2+y(idx).^2))/sqrt((x(idx)+2*pi).^2+y(idx).^2);
surf( xrange, yrange, z)

Sean de Wolski
Sean de Wolski il 21 Giu 2012
[x y] = meshgrid(1:20);
z = nan(size(x)); %preallocate (account for parts that don't meet anything)
idx = (x.^2+y.^2)<=pi^2; %where meets criteria?
z(idx) = sin(sqrt(x(idx).^2+y(idx).^2))./sqrt(x(idx).^2+y(idx).^2); %fill it with stuff
and repeat the last two lines for your other two consitions

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by