Removing the origin from the 3D meshgrid?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Suppose I want to plot level surfaces of a function of 3 variables, and suppose this function has a 1/(r^n) dependence. Where r = sqrt(X.^2 + Y.^2 + Z.^2) is the distance from the origin. Naturally I want to filter the origin from the [X,Y,Z] meshgrid to avoid singularities. How do I do this? Here is my attempt.
I thought about using the nonzero function on vectors x,y, and z and then forming the meshgrid but then that excludes entire coordinate planes.
%1) Create the grid
n = 50;
rmax = 2400;
x = linspace(-rmax,rmax,n+1);
y = linspace(-rmax,rmax,n+1);
z = linspace(-rmax,rmax,n+1);
[X,Y,Z] = meshgrid(x,y,z);
%2) Create R
R = sqrt(X.^2 + Y.^2 + Z.^2);
R1 = R.^(-1); %Create the reciprocal of R
idx = isnan(R1); %Find all the NaNs
R(idx) = []; %Delete all the NaN's in R, do the same for X,Y,Z
X(idx) = [];
Y(idx) = [];
Z(idx) = [];
Despite there being obvious singularities in R1 (because x,y,z each contain zero) I am still getting R,X,Y,and Z to have the same number of elements as they did before.
I would greatly appreciate any help.
0 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Surface and Mesh 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!