# Why does the array only work once?

3 views (last 30 days)
Marcos Dominguez on 3 Oct 2020
Commented: Star Strider on 3 Oct 2020
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
%Finding angle Phi of force P
%Finding force P
P = Mb/(BD*sind(90 - Phi));
%Finding Ma

Star Strider on 3 Oct 2020
Use element-wise division:
↑ ← HERE
and:
P = Mb./(BD*sind(90 - Phi));
↑ ← HERE
and element-wide multiplication:
↑ ← HERE
and the calculations do what you want them to do.
##### 2 CommentsShowHide 1 older comment
Star Strider on 3 Oct 2020
As always, my pleasure!

Alan Stevens on 3 Oct 2020
You need element by element multiplication and division:
% Givens
AB = 150;
BD = 200;
Theta = 20:120;
Mb = 2.5;
%Solutions
%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 *
Marcos Dominguez on 3 Oct 2020
Thank you sir. This fixed my code.

Sulaymon Eshkabilov on 3 Oct 2020
Hi,
You have overlooked a few dot operations. Here is the corrected part of your code:
%Finding angle Phi of force P
%Finding force P
P = Mb./(BD*sind(90 - Phi));
%Finding Ma
Marcos Dominguez on 3 Oct 2020
Thank you! It worked!