How I can make a function projection (A,B)?

16 vues (au cours des 30 derniers jours)
Sara Jam
Sara Jam le 12 Mar 2017
Commenté : Jan le 13 Mar 2017
For example i would to project vector A to B.
  1 commentaire
Jan
Jan le 12 Mar 2017
To me this sound like a homework question. Then please post, what you have tried so far.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 12 Mar 2017
Modifié(e) : Jan le 13 Mar 2017
The projection of a vector A onto a vector B has the same direction as the vector B, but a different length. When both are parallel, the length of A is not changed. When A and B are orthogonal, the resultung vector vanishes. You need the dot product to calculate this. The details are explained e.g. at Wiki: vector projection.
Please try this and post what you have done so far. If you have a specific question, you will get assistance here.
  2 commentaires
Sara Jam
Sara Jam le 12 Mar 2017
Modifié(e) : Jan le 13 Mar 2017
I made the function
P= projecton(A,B);
P= (dot(A,B)/norm(B)^2)*B
end
Is it correct ?
Jan
Jan le 13 Mar 2017
A function must start with the keyword "function":
function P = projection(A, B)
Then I'd insert a semicolon after the calculation to suppress the output to the command window. The calculations are correct.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Just for fun 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!

Translated by