I am attempting to use Mathematica to solve an optimization problem related to mechanism design (4-bar). The optimization problem is basically the following:
1) Solve these two simultaneous loop equations describing links in a mechanism as vectors:
Eq 1: $z(e^{i \alpha_2} - 1) + w(e^{i\beta_2} - 1) = \delta_2$
Eq 2: $z(e^{i \alpha_3} - 1) + w(e^{i\beta_3} - 1) = \delta_3$
In these equations what is know are both $\delta$'s, and both $\alpha$'s. Used mathematica to easily solve for $z$ and $w$ in terms of these parameters, so that the unknowns in the resultant equations are basically the $\beta$'s. $z$ and $w$ are obviously complex numbers, representing vectors representing links in a mechanism. The goal is to find both $\beta$'s such that the angle between these vectors will be minimized, ideally zero, as this will provide a high degree of mechanical advantage. I calculate this angle as
$\theta = cos^{-1}\left(\frac{w \cdot z}{|w||z|}\right)$
where $w$ and $z$ have been turned into pure vectors, like
$\text{vector form of z} = \left( \begin{array}{c} \text{Re}(z) \\ \text{Im}(z) \\ \end{array} \right)$
etc., and the dot indicates the dot product of vectors.
The mathematica code that I have up to this point is the following:
Subscript[[Delta], 2] = 9 E^(I*275 [Degree]);
Subscript[[Delta], 3] = 7.3 E^(I*-87 [Degree]);
Subscript[[Alpha], 2] = 30 [Degree];
Subscript[[Alpha], 3] = 0 [Degree];
Solve[{z (E^(I*Subscript[[Alpha], 2]) - 1) + w (E^(I Subscript[[Beta], 2]) - 1) == Subscript[[Delta], 2], z (E^(ISubscript[[Alpha], 3]) - 1) + w (E^(I Subscript[[Beta], 3]) - 1) == Subscript[[Delta], 3]}, {z, w}]
I then define variables z and w by setting them equal to the respective results of the solve operation. Then I go like
vecZ = ( { {FunctionExpand[Re[z]]}, {FunctionExpand[Im[z]]} } )
vecW = ( { {FunctionExpand[Re[w]]}, {FunctionExpand[Im[w]]} } )
AngleofInterest = Abs[ArcCos[Dot[vecZ, vecW]/(Norm[vecZ] Norm[vecW])]];
Minimize[{AngleofInterest, vecW[[2]] < 0}, {Subscript[[Beta], 2], Subscript[[Beta], 3]}]
the constraint vecW[[2]]<0
is just to do with the way we'd like the mechanism to look/operate.
When I try to run this code I wind up getting massive amounts of errors from the Dot operation telling me that the 'tensors' have 'incompatible shapes'. And also this error further down in the output:
Abs[ArcCos[0.0004018 {{51.0546},{9.37553}}.{{-47.9325},{1.14297}}]] is not a number at {Subscript[[Beta], 2],Subscript[[Beta], 3]} = {0.75721,0.152402}.
I will love you forever if you can educate me on this. Mechanism design is awful; it's so hard to get a design that works well so I have tried to formulate this as this optimization problem.. thanks!