Borrar filtros
Borrar filtros

How to plot equations with complex parts?

1 visualización (últimos 30 días)
Marco Froelich
Marco Froelich el 6 de Jul. de 2017
Comentada: KSSV el 6 de Jul. de 2017
I would like to plot the equation for a sphere, in which I had to reorganise to:
Z = sqrt(1 - X^2 - Y^2)
However I get a error saying my equation cannot be complex. How do I get around this?

Respuestas (1)

KSSV
KSSV el 6 de Jul. de 2017
You can use parametric form of equations of sphere and plot it as shown below:
Radius = 1 ;
Height = 1 ;
M = 50 ;
N = 50 ;
% Discretizing the theta and phi of the shell
nT = -linspace(0,2*pi,M+1) ;
nP = linspace(0,pi,N+1) ;
[T, P] = meshgrid(nT,nP) ;
% Convert grid to cartesian coordintes
X = Radius.*cos(T).*cos(P);
Y = Radius.*cos(T).*sin(P);
Z = Height*Radius.*sin(T) ;
%
surf(X,Y,Z)
  2 comentarios
Marco Froelich
Marco Froelich el 6 de Jul. de 2017
Yes I have seen this on other question/answers. But it is time consuming, and I have manyyyy spheres to plot. I was wondering if there was another way? It is quite dumb of Matlab not to recognize something such as:
x^2 + y^2 + z^2 = 1
KSSV
KSSV el 6 de Jul. de 2017
You can use sphere it is very fast and you can draw how many you want.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by