# Is there an error in the if else statement?

1 view (last 30 days)
SK dawn on 1 Nov 2021
Commented: SK dawn on 6 Nov 2021
when I try to enter the code the system does not run, it all happened when I added the if else statment so whats wrong?
>> % Known Variables:
L1 = 16.87; %cm
L2 = 60.35;
L3 = 16.81;
L4 = 63.06;
L5 = 42.62;
L7 = 19.64;
theta_1 = 105.47; %degree
theta_3 = 270;
theta_5 = 115.38;
theta_triangle = ;
v = 2.95;
for t = 0 : 0.1 : 10;
LA= 29.71+ v*t;
%solving for theta 6(actuator) and theta7
Zc = conj(Z);
A = L7*Zc;
B = Z*Zc +L7^2 -LA.^2;
C = L7*Z;
Q = (-B - sqrt(B^2 -4*A*C))/2*A;
Q_1 = (-B+ sqrt(B^2 -4*A*C))/2*A;
W= ((L7*Q)+Z)/LA;
W_1 = ((L7*Q_1)+Z)/LA;
if theta_7>90
theta_7_Final =360-theta_7;
else if theta_7>-180
theta_7_Final =180-theta_7_1;
else theta_7_Final =180-theta_7_1;
theta_6_Final = 180+theta_6_1
theta_4_Final= theta_7_Final - theta_triangle
end

Alan Stevens on 1 Nov 2021
Yes, among others! See:
L1 = 16.87; %cm
L2 = 60.35;
L3 = 16.81;
L4 = 63.06;
L5 = 42.62;
L7 = 19.64;
theta_1 = 105.47; %degree
theta_3 = 270;
theta_5 = 115.38;
theta_triangle = 100 ; %%%%%%%%%%%%%%%%%% You had no value here!
v = 2.95;
for t = 0 : 0.1 : 10
LA= 29.71+ v*t;
%solving for theta 6(actuator) and theta7
Zc = conj(Z);
A = L7*Zc;
B = Z*Zc +L7^2 -LA.^2;
C = L7*Z;
Q = (-B - sqrt(B^2 -4*A*C))/2*A;
Q_1 = (-B+ sqrt(B^2 -4*A*C))/2*A;
W= ((L7*Q)+Z)/LA;
W_1 = ((L7*Q_1)+Z)/LA;
if theta_7>90
theta_7_Final =360-theta_7;
elseif theta_7>-180 %%%%%%%%% elseif not else if
theta_7_Final =180-theta_7_1;
else
theta_7_Final =180-theta_7_1;
theta_6_Final = 180+theta_6_1;
theta_4_Final= theta_7_Final - theta_triangle;
end
end %%%%%%%%%%%%% There was an end missing
SK dawn on 6 Nov 2021
thank you