Input arguments for the cross function
1 次查看(过去 30 天)
显示 更早的评论
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
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!