matrix manipulation and transposing

1 view (last 30 days)
armani canady
armani canady on 13 Sep 2020
Commented: armani canady on 19 Sep 2020
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]

Answers (1)

Matt J
Matt J on 13 Sep 2020
Edited: Matt J on 13 Sep 2020
Because when v is a column vector and theta is a row vector, you get implicit expansion,
  8 Comments
Matt J
Matt J on 19 Sep 2020
Edited: Matt J on 19 Sep 2020
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 on 19 Sep 2020
thank you so much I finally understand. Have a nice day :)

Sign in to comment.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!