Asked by Pilar Jiménez
on 5 Oct 2016

I have to plot this equation to obtain a sphere

wave=I.*exp(j.*(((k.*x.*sin(TETA).*cos(PHI))))+((k.*y.*sin(TETA).*sin(PHI))))

but the comands mesh, surf, sphere not functioning me. I define the variables as following

puntos=200;

puntos_1=400;

teta=linspace(0,pi,puntos); %0 a 180°

phi=linspace(0,2*pi,puntos_1); %0 a 360°

[TETA,PHI]=meshgrid(teta,phi);

Could anyone help me, please?

Answer by Luca Fenzi
on 6 Oct 2016

This code works fine:

% PARAMETERS Of the model

I=1

x=1

y=1

k=1;

j=1;

%%Grid

puntos=200; puntos_1=400;

teta=linspace(0,pi,puntos); %0 a 180°

phi=linspace(0,2*pi,puntos_1); %0 a 360°

[TETA,PHI]=meshgrid(teta,phi);

% Model

wave=I.*exp(j.*(((k.*x.*sin(TETA).*cos(PHI))))+((k.*y.*sin(TETA).*sin(PHI))))

mesh(wave)

An other option should be instead of using teta,phi, you can use

[X,Y,Z]=sphere(N)

This will permit you to obtain a three dimensional grid of (N+1)x(N+1) points, but then your model wave must be changed from polar coordinate to Cartesian coordinate.

Pilar Jiménez
on 6 Oct 2016

Thanks Luca, The problem is that the j is an imaginary unit not a real number, for this I can't give the value of 1. And at the end of my code I must have a sphere with the absolute results of my equation wave that is on a matrix with different dimensions matrix. I have defined these variables:

I=1; %establecida por usuario

freq=30000000; %30 Mhz - no. de ondas/seg

c=300000000000; %m/seg

wlong=c/freq; %m

k=2*pi/wlong; %no. onda

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## David Goodmanson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/305947-how-can-i-plot-a-sphere-in-3d#comment_396301

## Pilar Jiménez (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/305947-how-can-i-plot-a-sphere-in-3d#comment_396535

Sign in to comment.