w=30; x=60; y=45; z=90; u=35; v=75;% "w,x,y,z are known" and "u and v are free choices". %
a12_c=cosd(w); a12_s=sind(w); a13_c=cosd(x); a13_s=sind(x);b12_c=cosd(y); b12_s=sind(y); b13_c=cosd(z); b13_s=sind(z);c12_c=cosd(u); c12_s=sind(u); c13_c=cosd(v); c13_s=sind(v);A=[1 0 1 0 -1 0; 0 1 0 1 0 -1; a12_c -a12_s c12_c -c12_s -b12_c b12_s;... a12_s a12_c c12_s c12_c -b12_s -b12_c; a13_c -a13_s c13_c -c13_s -b13_c b13_s;... a13_s a13_c c13_s c13_c -b13_s -b13_c];B=[1 0 1 0 1 0]';% disp(A); disp(B);
X=A\B; % X=[P Q R S T U]';
disp('The required matrix is:')disp(X);P=X(1,1); Q=X(2,1); R=X(3,1); S=X(4,1); T=X(5,1); U=X(6,1);a=sqrt(P.^2 + Q.^2); b=sqrt(R.^2 + S.^2); c=sqrt(T.^2 + U.^2);disp('The link lengths are:');fprintf('a= %.3f \n',a); fprintf('b= %.3f \n',b); fprintf('c= %.3f \n',c); fprintf('d= 1\n');theta1_1_a= acosd(P/a); theta1_1_b=-theta1_1_a; theta1_2_a= asind(Q/a); theta1_2_b=180-theta1_2_a;theta=0;fprintf('theta1_1_a= %.2f \n',theta1_1_a);fprintf('theta1_1_b= %.2f \n',theta1_1_b);fprintf('theta1_2_a= %.2f \n',theta1_2_a);fprintf('theta1_2_b= %.2f \n',theta1_2_b);if theta1_1_a==theta1_2_a || theta1_1_a==theta1_2_b theta=theta1_1_a; fprintf('theta= %.2f\n', theta1_1_a);elseif (theta1_1_b==theta1_2_a) || (theta1_1_b==theta1_2_b) theta=theta1_1_b;endfprintf('theta= %.2f\n', theta);
MATLAB: Though the code is pretty simple, still the value of theta remains 0 every time I execute the results with different values of w,x,y,z,u and v. The value of theta doesn’t change anytime.
homework
Related Question
- Roulette Algorithm Probability Loop
- What is wrong with the code ? The number and sort should only come up once until the deck is finished but when I run the code sometimes for example heart of seven comes twice or more. How can i fix this so the all the cards come up but only once
- Isn’t IF statement stopping Wile loop
- Filling up an m X n X o size matrix without loops
- Trouble Coding Kinematics Problem
Best Answer