matrix manipulation and transposing

조회 수: 6 (최근 30일)
armani canady
armani canady 2020년 9월 13일
댓글: armani canady 2020년 9월 19일
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에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by