Input arguments for the cross function

1 回表示 (過去 30 日間)
John Draper
John Draper 2016 年 1 月 18 日
コメント済み: John Draper 2016 年 1 月 20 日
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
  1 件のコメント
John Draper
John Draper 2016 年 1 月 20 日
Managed to do this by:
if true
[Nx,Ny,Nz]=surfnorm(X,Y,Z);
N=[Nx,Ny,Nz];
d=[dx,dy,dz];
i=(Ny.*dz - Nz.*dy);
j=(Nz.*dx - Nx.*dz);
k=(Nx.*dy - Ny.*dx);
% code
As this was in the required direction. end

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by