# Synthesis of Four-Link Initial Kinematic Chains with Spherical Pairs for Spatial Mechanisms
## 2 Materials and Methods
\begin{array}{c}\frac{\partial\mathbb{S}}{\partial X_{A}}=0;\ \ \frac{ \partial\mathbb{S}}{\partial Y_{A}}=0;\ \ \frac{\partial\mathbb{S}}{\partial Z_{A}}=0;\ \ \frac{ \partial\mathbb{S}}{\partial\mathbb{R}}=0;\\ \frac{\partial\mathbb{S}}{\partial x_{\mathbb{R}}}=0;\ \ \frac{\partial\mathbb{S}}{ \partial Y_{B}}=0;\ \ \frac{\partial\mathbb{S}}{\partial x_{\mathbb{R}}}=0;\ \ \frac{ \partial\mathbb{S}}{\partial x}=0;\\ \frac{\partial\mathbb{S}}{\partial x_{C}}=0;\ \ \frac{\partial\mathbb{S}}{ \partial Y_{C}}=0;\ \ \frac{\partial\mathbb{S}}{\partial x_{C}}=0;\ \ \frac{ \partial\mathbb{S}}{\partial x}=0\end{array}  \tag{18}\]  
To solve the system of equations formed by setting these partial derivatives to zero, we need to accomplish the following:  
* Expand each of the partial derivatives by differentiating the sum of the squared terms for each point with respect to the corresponding parameter;
* Simplify the resulting expressions to obtain a set of linear equations for each parameter being optimized;
* Numerically solve the system of equations using methods such as Gaussian elimination, the least squares method, or gradient descent. We are now working with a set of equations with weighted differences \(\Delta q_{i}^{(1)}\) for each \(i\). These equations aim to find the optimal values of \(X_{A}\), \(Y_{A}\), \(Z_{A}\), and \(R\) using the following system:  
\[\sum_{i=1}^{N}\Delta_{qi}^{(1)}(X_{Ai}-X_{A})=0 \tag{19}\]  
\[\sum_{i=1}^{N}\Delta_{qi}^{(1)}(Y_{Ai}-Y_{A})=0 \tag{20}\]  
\[\sum_{i=1}^{N}\Delta_{qi}^{(1)}(Z_{Ai}-Z_{A})=0 \tag{21}\]  
\[\sum_{i=1}^{N}\Delta_{qi}^{(1)}R=0 \tag{22}\]  
These equations are essentially normal equations that come from minimizing the sum of squared weighted differences \(S\). Each equation corresponds to a specific parameter (either \(X_{A}\), \(Y_{A}\), \(Z_{A}\), or \(R\)) that we are trying to optimize [18]. Each equation represents the sum of weighted differences between the coordinates \(X_{A}\), \(Y_{A}\), \(Z_{A}\) and their respective target values \(X_{Ai}\), \(Y_{Ai}\), \(Z_{Ai}\), weighted by the difference function \(\Delta q_{i}^{(1)}\). The goal is to adjust the coordinates so that the sum of these weighted differences is minimized (i.e., set each sum to zero). This equation sums the weighted differences over all positions. Since \(\Delta q_{i}^{(1)}\) is a function of \(X_{A}\), \(Y_{A}\), \(Z_{A}\), and \(R\), this equation ensures that the weighted differences balance out when summed across all positions:  
\[\sum_{i=1}^{N}\Delta_{qi}^{(1)}=0\]  
These equations ensure that the weighted differences \(\Delta q_{i}^{(1)}\) are balanced with respect to the coordinates \(X_{A}\), \(Y_{A}\), \(Z_{A}\). Each equation adjusts one of the coordinates of point \(A\) to minimize the sum of the squared weighted differences. \[\sum_{i=1}^{N}\Delta_{qi}^{(1)}X_{Ai}=0 \tag{23}\]  
\[\sum_{i=1}^{N}\Delta_{qi}^{(1)}Y_{Ai}=0 \tag{24}\]  
\[\sum_{i=1}^{N}\Delta_{qi}^{(1)}Z_{Ai}=0 \tag{25}\]  
\[\sum_{i=1}^{N}\Delta_{qi}^{(1)}R=0\]  
This equation ensures that the radius \(R\) is adjusted to minimize the weighted differences across all positions. We propose a system of equations involving sums of square terms and cross-products for the measured differences. The goal is to simplify these conditions to find the optimal values of the parameters. Let us consider the structure of the equations step by step.