I need help programming a script, in MATLAB, that for assigned values compute the optimal transmission angle of a crank-rocker mechanism.The parameters are:$L$: crank's angle of oscillation, for example from -20 to 150$m$: rocker's angle of oscillation, it's a fixed value.$t$:  $\tan(L/2)$$u$: $\tan((L-m)/2)$$v$: $\tan(m/2)$There is a condition on $L$, $L<(90+(m/2))$The equation is a cubic:$$Q^3 + 2Q^2 - t^2 Q- \frac{t^2(1+t^2)}{u^2}$$where $Q=t^2/x^2$.The roots of $Q$ must be real and positive.$x$ is the variable and it should satisfy the following inequalities:$x^2 \geq 1$ and $x^2 \leq u^2 t^2$.Now the lengths of the 4-bar are\begin{align}a &= \sqrt{\frac{v^2}{1 + v^2}}\crb &= \sqrt{\frac{x^2 v^2}{1 + v^2}}\crc &= \sqrt{\frac{x^2 + t^2}{1 + t^2}}\crd &= \sqrt{\frac{u^2 + x^2}{1 + u^2}}\end{align}I solve the equation for $Q$ then calculate $x$. Now the transmission angle (max and min) depends on $a(x)$, $b(x)$, $c(x)$ and $d(x)$. I have a different transmission angle (max and min) for all the different values of crank's angle of oscillation. For example as, Istated previously from $-20$ to $(90+(m/2))$ (the lower bound is discretionary)$$\begin{aligned} \mathit{angtrasm}_{\min}&= \arccos\left({\frac{b^2 + c^2-(d-a)^2}{2bc}}\right)\\\mathit{angtrasm}_{\max} &= \arccos\left({\frac{b^2 + c^2-(d + a)^2}{2bc}}\right)\end{aligned}$$My code is the following% Compute transmission angle and lengths of barsclear allm = 32;   %rockers oscillationi = 1;f = 1;for l = 1: (90 + m/2 );  % cranks oscillation -pi (there is a problem here i cant start from -20 for example)  L(i) = l + 180 ;       %cranks oscillation  t = tand(L(i)/2);  u = tand((L(i)-m)/2);  v = tand(m/2);  p = [1 2 -(t^2) -((t^2 + (1 + t^2))/(u^2))];  if L(i) = = m    fprintf('Value of cranks oscillation is not acceptable \n' , L(l));  else    Q = roots(p);    for j = 1:3      if isreal(Q(j)) && Q(j)>0        x = abs(t/sqrt(Q(j)));        if x^2 > = 1 && x^2 < = u^2*t^2          a = sqrt(v^2/(1 + v^2));          b = sqrt(x^2*v^2/(1 + v^2));          c = sqrt((x^2 + t^2)/(1 + t^2));          d = sqrt((u^2 + x^2)/(1 + u^2));          angtrasm_min(f) = acosd((b^2 + c^2-(d-a)^2)/(2*b*c));          angtrasm_max(f) = acosd((b^2 + c^2-(d + a)^2)/(2*b*c));          scarto_min(f) = abs(90-angtrasm_min(f));          scarto_max(f) = abs(90-angtrasm_max(f));          theta(f) = L(i);          r1(f) = a;          r2(f) = b;          r3(f) = c;          r4(f) = d;          fprintf('The max transmision angle is %d when theta is %d\n',angtrasm_max(f),L(i));          fprintf('The max transmision angle is %d when theta is %d\n',angtrasm_min(f),L(i));          fprintf('.................................\n');          f = f + 1;        end      end    end  end  i = i + 1;end
Optimal synthesis of crankrocker linkages
optimization