Why does the array only work once?

1 回表示 (過去 30 日間)
Marcos Dominguez
Marcos Dominguez 2020 年 10 月 3 日
コメント済み: Star Strider 2020 年 10 月 3 日
Hey guys,
I'm having trouble with the code in trying to find the angle phi. The calculation for AD uses Theta as I intended, but when calculating Phi, I only get one answer instead of multiple. This makes the rest of my code incorrect. Any suggestions?
% Givens
AB = 150;
BD = 200;
Theta = 20:120;
Mb = 2.5;
%Solutions
AD = sqrt(BD^2 + AB^2-2*BD*AB*cosd(Theta));
%Finding angle Phi of force P
Phi = asind(AB*sind(Theta)/AD);
%Finding force P
P = Mb/(BD*sind(90 - Phi));
%Finding Ma
Ma = P * AD;

採用された回答

Star Strider
Star Strider 2020 年 10 月 3 日
Use element-wise division:
Phi = asind(AB*sind(Theta)./AD);
↑ ← HERE
and:
P = Mb./(BD*sind(90 - Phi));
↑ ← HERE
and element-wide multiplication:
Ma = P .* AD;
↑ ← HERE
and the calculations do what you want them to do.
  2 件のコメント
Marcos Dominguez
Marcos Dominguez 2020 年 10 月 3 日
Thank you! This fixed my code, just right!
Star Strider
Star Strider 2020 年 10 月 3 日
As always, my pleasure!

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

その他の回答 (2 件)

Alan Stevens
Alan Stevens 2020 年 10 月 3 日
You need element by element multiplication and division:
% Givens
AB = 150;
BD = 200;
Theta = 20:120;
Mb = 2.5;
%Solutions
AD = sqrt(BD^2 + AB^2-2*BD*AB*cosd(Theta));
%Finding angle Phi of force P
Phi = asind(AB*sind(Theta)./AD); %%%%% ./ not just /
%Finding force P
P = Mb./(BD*sind(90 - Phi)); %%%%% ./ not just /
%Finding Ma
Ma = P.* AD; %%%%% .* not just *
  1 件のコメント
Marcos Dominguez
Marcos Dominguez 2020 年 10 月 3 日
Thank you sir. This fixed my code.

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


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2020 年 10 月 3 日
Hi,
You have overlooked a few dot operations. Here is the corrected part of your code:
%Finding angle Phi of force P
Phi = asind(AB*sind(Theta)./AD);
%Finding force P
P = Mb./(BD*sind(90 - Phi));
%Finding Ma
Ma = P.*AD;
  1 件のコメント
Marcos Dominguez
Marcos Dominguez 2020 年 10 月 3 日
Thank you! It worked!

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by