I need help with MATLAB programming. I was working on a program that would give the both values of sin(angle) and cos(angle). For example, if you have eta = 30 degrees. For cosine, cos(30) = cos(330). For sine, sin(30) = sin(150). My program would give you two different sets of angles when you input one set of angles. If you input 30 degrees in cos, my program would give you 30 and 330 as the result. I am getting a problem when I try to do that for sin though. In the following program everything runs smoothly but my angle eta2 only gives two different sets of angle for the first angle I inputted. The second set to the ninth set of angle for eta2 are incorrect. Can you help me fix the problem? eta1 = [135.3767 136.7215 138.0672 139.4093 140.7436 142.0707 143.3915 144.7063 146.0159]; eta2 = [-44.6233 -43.2785 -41.9328 -40.5907 -39.2564 -37.9293 -36.6085 -35.2937 -33.9841]; % For cos eta1 = [abs(eta1); 360-abs(eta1)]; % For sin for i = length(9) if 0 <= eta2(i) && eta2(i) <= 180 eta2(1,i) = eta2(i); eta2(2,i) = 180 - eta2(i); elseif 180 < eta2(i) && eta2(i) <= 360 eta2(1,i) = eta2(i); eta2(2,i) = 360 - (eta2(i) - 180); elseif -360 < eta2(i) && eta2(i) <= -180 eta2(1,i) = 360 + eta2(i); eta2(2,i) = 180 - (360 + eta2(i)); elseif -180 < eta2(i) && eta2(i) <= 0 eta2(1,i) = 360 + eta2(i); eta2(2,i) = 360 + (180 - eta2(i)); end end eta1 eta2 % The first column of eta2 is correct. But starting from the second to the ninth column, it is incorrect. % There might be a problem with the for loop.
I need help with MATLAB
I am getting a problem when I try to do that for sin though. In the following program everything runs smoothly but my angle eta2 only gives two different sets of angle for the first angle I inputted. The second set to the ninth set of angle for eta2 are incorrect. Can you help me fix the problem?
eta1 = [135.3767 136.7215 138.0672 139.4093 140.7436 142.0707 143.3915 144.7063 146.0159];
eta2 = [-44.6233 -43.2785 -41.9328 -40.5907 -39.2564 -37.9293 -36.6085 -35.2937 -33.9841];
% For cos
eta1 = [abs(eta1); 360-abs(eta1)];
% For sin
for i = length(9)
if 0 <= eta2(i) && eta2(i) <= 180
eta2(1,i) = eta2(i);
eta2(2,i) = 180 - eta2(i);
elseif 180 < eta2(i) && eta2(i) <= 360
eta2(1,i) = eta2(i);
eta2(2,i) = 360 - (eta2(i) - 180);
elseif -360 < eta2(i) && eta2(i) <= -180
eta2(1,i) = 360 + eta2(i);
eta2(2,i) = 180 - (360 + eta2(i));
elseif -180 < eta2(i) && eta2(i) <= 0
eta2(1,i) = 360 + eta2(i);
eta2(2,i) = 360 + (180 - eta2(i));
end
end
eta1
eta2
% The first column of eta2 is correct. But starting from the second to the ninth column, it is incorrect.
% There might be a problem with the for loop.
Step by step
Solved in 4 steps with 1 images