Cross product of two vectors(function)
Afficher commentaires plus anciens
I need to create a function that calculates the cross product of two vectors V1 and V2.
V1 X V2=(Vy1*Vz2 - Vy2*Vz1)i + (Vz1*Vx2 - Vz2*Vx1)j + (Vx1*Vy2 - Vx2*Vy1)k
V1= Vx1i + Vy1j + Vz1k [-2,4,.5]
V2= Vx2i + Vy2j + Vz2k [.5,3,2]
Im completely lost at why i cant get this to work. The function should be something like crossprod[i j k] but i dont know how to implement i j k as inputs, for both vectors. Heres what i tried to do, not using i j k as inputs.
function [result]=cross_product(V1,V2)
%CROSS_PRODUCT calculates the cross product of two vectors.
V1=[v1x,v1y,v1z];
V2=[v2x,v2y,v2z];
i=(v1y*v2z - v2y*v1z);
j=(v1z*v2x - v2z*v1x);
k=(v1x*v2y - v2x*v1y);
result=i+j+k;
end
Réponse acceptée
Plus de réponses (1)
James Tursa
le 10 Avr 2011
0 votes
OK. I will make a stronger statement this time. i+j+k is the wrong answer. You need to return a 3-vector, and i+j+k is not a 3-vector. Check the above code result against the built-in cross function and you will see what I mean. The above code result is wrong. Then reconsider my advice to return result=[i,j,k].
1 commentaire
Paulo Silva
le 10 Avr 2011
I fixed my answer, thanks.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!