MATLAB: Plotting an Inverse Square Vector Field in 3-Space

inverse square fieldsmaxwell's equations

I am have paramaterized, spherical coordinates in terms of x,y,&z, and trying to plot the vector field. First I tried simplifying these expresssions with 'syms' by defining 'phi' , 'theta' , and 'r' in terms of (x,y,z), but I had no better luck. I downloaded the 'symbolic' package for Octave. I am completely new to Octave/Matlab. So I am probably messing up on something simple. I have spent hours trying to figure it out myself, but I am at a loss.
Here is an example of one of my attempts:
[x,y,z] = meshgrid(-1:0.1:1);
u = cos(atan(y/x)).*sin(acos(z./sqrt(x.^2+y.^2+z.^2));
v = sin(atan(y/x)).*sin(acos(z./sqrt(x.^2+y.^2+z.^2));
w = cos(acos(z./sqrt(x.^2+y.^2+z.^2)));
figure
quiver3(x,y,z,u,v,w)

Best Answer

You need to use y./x rather than y/x