MATLAB: Does the array only work once


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;
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;

Best Answer

  • Use element-wise division:
    Phi = asind(AB*sind(Theta)./AD);
    ↑ ← HERE
    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.