matrix manipulation and transposing

2 次查看(过去 30 天)
so, I am writing this code to Create a table showing the maximum height for the following values of v and q: v = 10, 12, 14, 16, 18, 20 m/s q= 50, 60, 70, 80 The rows in the table should correspond to the speed values, and the column should correspond to the angles. where g=2.8. The formula for the question is v^2*sin(thetha)^2/2*g.
my question is why did i need to transpose v in my code so that it would work?
v=[2:2:20]
g=2.8
thetha=[50:10:80]
h=(v'.^2).*(sind(thetha).^2)./(2*g)
table=[0 thetha; v' h]

回答(1 个)

Matt J
Matt J 2020-9-13
编辑:Matt J 2020-9-13
Because when v is a column vector and theta is a row vector, you get implicit expansion,
  8 个评论
Matt J
Matt J 2020-9-19
编辑:Matt J 2020-9-19
No, the reason you would do operations between a column vector and a row vector is that you want to take advantage of one of the many uses of implict expansion, illustrated at the link I gave you. The way you choose which vector will be a column and which will be a row just depends on what shape you want the resulting matrix to have and how its contents should be organized. It is not a matter of which vector is longest, as the following examples show:
>> a=[1 2 3]; b=[4 5 6 7];
>> c=a.'+b
c =
5 6 7 8
6 7 8 9
7 8 9 10
>> c=a+b.'
c =
5 6 7
6 7 8
7 8 9
8 9 10
>> c=c+a
c =
6 8 10
7 9 11
8 10 12
9 11 13
>> c=c+b.'
c =
10 12 14
12 14 16
14 16 18
16 18 20
armani canady
armani canady 2020-9-19
thank you so much I finally understand. Have a nice day :)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by