0

I want to plot the following function B(r,theta,phi) in spherical coordinates.

Bo     = 1;
a      = 1;      % m
lambda = 1; % m^-1

syms r theta;

Br = 2*Bo*(a/r)*besselj(1,lambda*r)*cos(theta)
Bth = -Bo*(a/r)*diff(r*besselj(1,lambda*r),r)*sin(theta)
Bph = lambda*a*Bo*besselj(1,lambda*r)*sin(theta)

[Bx,By,Bz]=sph2cart(Bth,Bph,Br);

x=linspace(0,a);
y=linspace(0,a);
z=linspace(0,a);

quiver3(x,y,z,Bx,By,Bz)

When I run the above code, I receive the following warning and error.

Warning: Using only the real component of complex data. 
> In getRealData (line 14)
  In quiver3parseargs (line 87)
  In quiver3HGUsingMATLABClasses (line 41)
  In quiver3 (line 41)
  In taylor_state (line 19) 
Error using quiver3 (line 43)
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use VPA.

Error in taylor_state (line 19)
quiver3(x,y,z,Bx,By,Bz)
IKavanagh
  • 6,089
  • 11
  • 42
  • 47
Peter
  • 367
  • 1
  • 4
  • 12
  • I'm guessing `Bx`, `By`, and `Bz` are symbolic. Did you try `quiver3` with [`vpa`](http://www.mathworks.com/help/symbolic/vpa.html), like the error told you to? – sco1 Oct 01 '15 at 12:49
  • Either use `vpa` as recommended, or simply drop symbolic expressions and define your domain explicitely: `r=linspace(0,a); theta=linspace(0,2*pi);`, then replace all your `*` and `/` operators by their element-wise expression: `.*` and `./` – Hoki Oct 01 '15 at 13:18

0 Answers0