Input arguments for the cross function
1 view (last 30 days)
Show older comments
Hi, I'm trying to use the cross function to give me the cross product of two sets of vectors at points on the surface of the sphere.
I keep getting the error "A and B must have at least one dimension of length 3". I'm not entirely sure what this means and what I should do to my data to correct it?
I have checked using 'whos' and both my A and B are of the 'double' data type.
Here is my code:
if true
R=22; phi=linspace(0,pi,50); theta=linspace(pi/2,pi/2,50);
[phi,theta]=meshgrid(phi,theta);
X=R*sin(phi).*cos(theta); Y=R*sin(phi).*sin(theta); Z=R*cos(phi);
con=50; T=Z./R;
U=3*con.*X.*Z./R.^5 %mag field in x
V=3*con.*Y.*Z./R.^5; %mag field in y
W=con.*((3*Z.^2 -(R.^2)))./R.^5;
hold
dx=gradient(X); dy=gradient(Y); dz=gradient(Z)
A=U.*dx; B=V.*dy; C=W.*dz;
k=A+B+C;
k1=k./sqrt(dx.*dx +dy.*dy + dz.*dz);
projx=k1.*dx; projy=k1.*dy; projz=k1.*dz;
%figure
%quiver3(X,Y,Z,projx,projy,projz,'color',[0,0,0])
proj=[projx projy projz];
[Nx,Ny,Nz]=surfnorm(X,Y,Z);
N=[Nx Ny Nz];
j1=cross(N,proj);
% code
end
also I'm assuming that if I wanted the components of the resulting cross product vector individually i would code:
if true
j1x=cross(N,proj,1)
j1y=cross(N,proj,2)
j1z=cross(N,proj,3)
% code
end
Thanks in advance for your help
Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!