Data Analysis Write a Porgram

1 次查看(过去 30 天)
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-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
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
V1 = input('Vector V1= ');
V2 = input('Vector V2= ');
frstprt= dot(V1,V2)/norm(V1,2)^2;
scndprt = frstprt.*V1;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by