How do i multiply 2 increasing variables

Hello everyone i was wondering if u could help me multiply these two increasing variables. They just do not multiply correctly
v0 = (10:1:20);
theta = (30:1:40);
v0_x = v0.*cosd(theta);
v0_y = v0.*sind(theta);

6 件のコメント

dpb
dpb 2020 年 8 月 14 日
What do you think is incorrect?
It may not be what you were trying to compute, but the result of the two expressions is certainly what would be expected by MATLAB syntax.
Steven Lord
Steven Lord 2020 年 8 月 14 日
What does "do not multiply correctly" mean in this context?
  • Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
  • Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
  • Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support using the telephone icon in the upper-right corner of this page so we can investigate.
Sara Boznik
Sara Boznik 2020 年 8 月 14 日
I think is correct.
Ilker Enes Çirkin
Ilker Enes Çirkin 2020 年 8 月 14 日
i was expecting the code to create the solutions like this,
10*cosd(30) 11*cosd(30) 12*cosd(30) 13*cosd(30) ....
10*cosd(31) 11*cosd(31) 12*cosd(31) ......
10*cosd(32) 11*cosd(32) ......
10*cosd(33) .......
KSSV
KSSV 2020 年 8 月 14 日
To get this you need to use symbolic tool box.
Sara Boznik
Sara Boznik 2020 年 8 月 14 日
for v0 = 10:1:20;
for theta = 30:1:40;
v0_x = v0.*cosd(theta)
v0_y = v0.*sind(theta)
end
end
Do you need this?

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

 採用された回答

Shae Morgan
Shae Morgan 2020 年 8 月 14 日
編集済み: Shae Morgan 2020 年 8 月 14 日

0 投票

Is this more what you were looking for?
v0 = (10:1:20);
theta = (30:1:40);
for i= 1:length(v0)
for j = 1:length(theta)
v0_x(i,j)=v0(i)*cosd(theta(j));
v0_y(i,j)=v0(i)*sind(theta(j));
end
end
v0_x
v0_y

4 件のコメント

Ilker Enes Çirkin
Ilker Enes Çirkin 2020 年 8 月 14 日
yes this is correct, thank you
KSSV
KSSV 2020 年 8 月 14 日
If you wanted that..simply use:
v0 = (10:1:20);
theta = (30:1:40);
[v0,theta] = meshgrid(v0,theta) ;
v0_x = v0.*cosd(theta);
v0_y = v0.*sind(theta);
Ilker Enes Çirkin
Ilker Enes Çirkin 2020 年 8 月 14 日
i am not familiar with meshgrid
Shae Morgan
Shae Morgan 2020 年 8 月 14 日
meshgrid() is another great solution here
x=[1 2 3]; %x array
y=[3 2 1]; %y array
[X,Y]=meshgrid(x,y)
%X is a length(y) long set rows of x
%Y is a length(x) long set of columns of y
using these matrices with the point multiplication will give the same outcome. The for-loops feel more intuitive and are visually understandable as you read through the code, but meshgrid requires fewer lines and a little more understanding of what it's doing.
In the end it's preference. I prefer code readability (or familiarizing yourself with new functions so you can improve readability!)

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

その他の回答 (1 件)

Bruno Luong
Bruno Luong 2020 年 8 月 14 日
編集済み: Bruno Luong 2020 年 8 月 14 日

0 投票

v0 = (10:1:20);
theta = (30:1:40);
v0_x = v0.*cosd(theta.'); % horizontal .* vertical vectors
v0_y = v0.*sind(theta.');

カテゴリ

ヘルプ センター および File ExchangeHistorical Contests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by