matrix manipulation and transposing

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 日

0 投票

Because when v is a column vector and theta is a row vector, you get implicit expansion,

8 件のコメント

armani canady
armani canady 2020 年 9 月 15 日
yeah but what is still dont understand is how v is a column vector and thetha isnt because when i run my code i get two vectors in my command window.
v =
2 4 6 8 10 12 14 16 18 20
g =
2.8000
thetha =
50 60 70 80
h =
0.4192 0.5357 0.6307 0.6927
1.6766 2.1429 2.5229 2.7710
3.7724 4.8214 5.6766 6.2347
6.7066 8.5714 10.0917 11.0840
10.4790 13.3929 15.7683 17.3187
15.0898 19.2857 22.7063 24.9389
20.5388 26.2500 30.9058 33.9446
26.8262 34.2857 40.3667 44.3358
33.9520 43.3929 51.0891 56.1125
41.9160 53.5714 63.0730 69.2747
table =
0 50.0000 60.0000 70.0000 80.0000
2.0000 0.4192 0.5357 0.6307 0.6927
4.0000 1.6766 2.1429 2.5229 2.7710
6.0000 3.7724 4.8214 5.6766 6.2347
8.0000 6.7066 8.5714 10.0917 11.0840
10.0000 10.4790 13.3929 15.7683 17.3187
12.0000 15.0898 19.2857 22.7063 24.9389
14.0000 20.5388 26.2500 30.9058 33.9446
16.0000 26.8262 34.2857 40.3667 44.3358
18.0000 33.9520 43.3929 51.0891 56.1125
20.0000 41.9160 53.5714 63.0730 69.2747
>>
Matt J
Matt J 2020 年 9 月 15 日
編集済み: Matt J 2020 年 9 月 15 日
A real-valued row vector v is turned into a column vector when you do v.' or v'
armani canady
armani canady 2020 年 9 月 18 日
I understand the v is a column vector. Maybe I phrased my question wrong why did I have to turn v into a column vector in order to use the formula. I thought that thetha and v were both row vectors; thus, I could times them.
Matt J
Matt J 2020 年 9 月 18 日
編集済み: Matt J 2020 年 9 月 18 日
If you do .* or ./ operations on vectors of the same shape, e.g., both row vectors, then the operations will be done element-wise,
>> a=[1,2,3]; b=[10,20,30];
>> c=a.*b %This means c(i)=a(i)*b(i)
c =
10 40 90
Conversely, if a is a column vector and b is a row vector, you would be implementing c(i,j)=a(i)*b(j)
>> c = a.' .* b %This gives c(i,j)=a(i)*b(j)
c =
10 20 30
20 40 60
30 60 90
This happens because of a Matlab mechanism called implicit expansion.
armani canady
armani canady 2020 年 9 月 19 日
so, the reason I had to turn transpose v is because they were not of the same shape? If this logic is correct then will I always need to transpose the vector with the most amount of element to prefrom * and / ?
armani canady
armani canady 2020 年 9 月 19 日
also, thank you for your time. You ar helping me a lot I appericate you.
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 :)

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

カテゴリ

質問済み:

2020 年 9 月 13 日

コメント済み:

2020 年 9 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by