Cross Product of an Array
34 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hollis Williams
le 22 Avr 2019
Commenté : James Tursa
le 22 Avr 2019
I have an array of size 3 x 100 and I basically want to create a new array where I take each column vector in the array and compute the cross product with the same vector each time to create another array of size 3 x 100, so in this case I take every vector and form the cross product with [0 0 1]'. What would be the easiest way of doing this?
0 commentaires
Réponse acceptée
James Tursa
le 22 Avr 2019
Modifié(e) : James Tursa
le 22 Avr 2019
M = your 3xN matrix
v = your 3x1 vector
result = cross(M,repmat(v,1,size(M,2)));
10 commentaires
Plus de réponses (1)
Matt J
le 22 Avr 2019
Modifié(e) : Matt J
le 22 Avr 2019
This way avoids repmatting, which may be desirable when N is large.
M = your 3xN matrix
v = your 3x1 vector
result=xprodmat(v)*M./vecnorm(M);
where
function A=xprodmat(a)
%Matrix representation of a cross product
%
% A=xprodmat(a)
%
%in:
%
% a: 3D vector
%
%out:
%
% A: a matrix such that A*b=cross(a,b)
if length(a)<3, error 'Input must be a vector of length 3'; end
ax=a(1);
ay=a(2);
az=a(3);
A=zeros(3);
A(2,1)=az; A(1,2)=-az;
A(3,1)=-ay; A(1,3)=ay;
A(3,2)=ax; A(2,3)=-ax;
end
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!