How to write a program for finding the ortogonal projection of a given vector V1 on another given vector V2??
How should ı do? Which Matlab commands should i use?

5 件のコメント

Jan
Jan 2022 年 11 月 5 日
How would you do this with pencil and paper?
John D'Errico
John D'Errico 2022 年 11 月 5 日
Jan's question is the perfect one: I.e., How would you do it on paper, as if you know how to do that, then you can trivially write the MATLAB code. If you don't understand that, then this is surely a homework problem for you, and you need to make an effort.
Mustafa Furkan SAHIN
Mustafa Furkan SAHIN 2022 年 11 月 6 日
I know orthogonal projection is done like this, but I have no idea how to write this in matlab. If I define Vector V1 and V2, multiply as V1.*V2 then divide to V1.^2. Then multiply the result from here by Vector 1. Will i get correct results?
Jan
Jan 2022 年 11 月 6 日
V1 .* V2 is the elementwise multiplication. You want the dot product instead: V1 * V2.' or dot(V1, V2). Mathematically this can be expressed as sum(V1 .* V2) also.
V1 .^ 2 squares each element, but you want the norm of the vectors: norm(V2)^2. This can be written as sum(V1 .* V1) also.
Try it. There are some different possible commands only, so you can solve this by "gunshot programming": modify the code until the result is as expected.
Mustafa Furkan SAHIN
Mustafa Furkan SAHIN 2022 年 11 月 6 日
編集済み: Mustafa Furkan SAHIN 2022 年 11 月 6 日
V1 = input('Vector V1= ');
V2 = input('Vector V2= ');
frstprt= dot(V1,V2)/norm(V1,2)^2;
scndprt = frstprt.*V1;
I got the correct result with this Matlab program.Thank you very much for helping me understand the matlab code.

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

 採用された回答

Mustafa Furkan SAHIN
Mustafa Furkan SAHIN 2022 年 12 月 11 日

1 投票

V1 = input('Vector V1= ');
V2 = input('Vector V2= ');
frstprt= dot(V1,V2)/norm(V1,2)^2;
scndprt = frstprt.*V1;

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

リリース

R2022b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by