# Solving 5 equations with 5 variable using Newton Raphson method

I have 5 equations with 5 variables $$X_1$$, $$X_2$$, $$X_3$$, $$X_4$$, and $$X_5$$, namely
\begin{align} a_{11}X_1 + a_{12}X_2 + a_{13}X_3 + a_{14}X_4 \sin X_5 &= b_1,\\ a_{21}X_1 + a_{22}X_2 + a_{23}X_3 + a_{24}X_4\sin X_5 &= b_2,\\ a_{31}X_1 + a_{32}X_2 + a_{33}X_3 + a_{34}X_4\cos X_5 &= b_3,\\ a_{41}X_1 + a_{42}X_2 + a_{43}X_3 + a_{44}X_4 \sin X_5 &= b_4,\\ a_{51}X_1 + a_{52}X_2 + a_{53}X_3 + a_{54}X_4\sin X_5 &= b_5. \end{align}

I need to solve it for $$X_1$$, $$X_2$$, $$X_3$$, $$X_4$$, and $$X_5$$ using Newton Raphson Method. Here \begin{align} a_{11} &= a_{12}=s_1, & a_{13}&=1, & a_{14}&=-1, \\ a_{21} &= a_{22}=s_2, & a_{23}&=1, & a_{24}&=-2, \\ a_{31} &= -a_{32}=s_3, & a_{33}&=0,& a_{34}&=1, \\ a_{41} &= a_{42}=s_{44}, & a_{43}&=1/2, & a_{44}&=-s_{45} ,\\ a_{51} &= a_{52}=s_5,& a_{53}&=0, & a_{54}&=-1. \end{align}

Using Newton Raphson Method I have got a 5x5 matrix for the above equations. So I have got an equation like $$a_{ij}X_j = b_j$$.

How to assume the initial conditions for the next step? how many iteration I should do?

In addition, I request your suggestion for other method I can apply here. Thanks

We define the function $$F:\mathbb{R}^5 \to \mathbb{R}^5$$ as $$F(x)=\begin{pmatrix} a_{11}x_1 + a_{12}x_2 + a_{13}x_3 + a_{14}x_4\sin x_5 - b_1 \\ a_{21}x_1 + a_{22}x_2 + a_{23}x_3 + a_{24}x_4\sin x_5 - b_2 \\ a_{31}x_1 + a_{32}x_2 + a_{33}x_3 + a_{34}x_4\cos x_5 - b_3 \\ a_{41}x_1 + a_{42}x_2 + a_{43}x_3 + a_{44}x_4\sin x_5 - b_4 \\ a_{51}x_1 + a_{52}x_2 + a_{53}x_3 + a_{54}x_4\sin x_5 - b_5 \end{pmatrix}$$ and we want to find $$x^*$$ such that $$F(x^*)=0$$. To apply the NRM we only need to compute the Jacobian of $$F$$ $$J_F(x)=\biggl(\frac{\partial F_i}{\partial x_j}\biggr)_{i,j} =\begin{pmatrix} a_{11} & a_{12} & a_{13} & a_{14}\sin x_5 & a_{14}x_4 \cos x_5 \\ a_{21} & a_{22} & a_{23} & a_{24}\sin x_5 & a_{24}x_4 \cos x_5 \\ a_{31} & a_{32} & a_{33} & a_{34}\cos x_5 & -a_{34}x_4 \sin x_5 \\ a_{41} & a_{42} & a_{43} & a_{44}\sin x_5 & a_{44}x_4 \cos x_5 \\ a_{51} & a_{52} & a_{53} & a_{54}\sin x_5 & a_{54}x_4 \cos x_5 \end{pmatrix}.$$
At this point, the NRM iteration is just $$x^{k+1} = x^{k}-J_F(x^k)^{-1}F(x^k).$$ Note that I use superscripts (e.g., $$x^k$$) to denote iterations, so that we don't get confused with the $$i$$th entry of the vector $$x$$, i.e. $$x_i$$.
If you can use some library for solving systems of linear equations, it may be computationally more convenient to solve the system $$J_F(x^k) y = F(x^{k})$$ and then set $$x^{k+1}=x^k-y$$.
Concerning the starting point $$x^0$$, the usual suggestion is that you should use a rough estimate of the root of the function, if you know it. Otherwise, you can start from any point, run some iterations and start over from another point if the algorithm gets stuck. Also, your solution may vary depending on the starting point (your system is not linear and can have multiple solutions, see below). As for the number of iterations, it'll depend a lot on the starting point and on how "well behaved" your function is. I suggest you to read the Wikipedia entry about the NRM, it provides a good analysis.
Another possible way to solve the problem, that does not involve iterative methods, is to introduce two new variables $$y_1$$ and $$y_2$$ and solve the linear system of equations \begin{align} a_{11}x_1 + a_{12}x_2 + a_{13}x_3 + a_{14}y_1 &= b_1 \\ a_{21}x_1 + a_{22}x_2 + a_{23}x_3 + a_{24}y_1 &= b_2 \\ a_{31}x_1 + a_{32}x_2 + a_{33}x_3 + a_{34}y_2 &= b_3 \\ a_{41}x_1 + a_{42}x_2 + a_{43}x_3 + a_{44}y_1 &= b_4 \\ a_{51}x_1 + a_{52}x_2 + a_{53}x_3 + a_{54}y_1 &= b_5 \end{align} followed by the new system \begin{align} x_4 \sin x_5 &= y_1 \\ x_4 \cos x_5 &= y_2 \end{align} from which we get \begin{align} x_5 &= \arctan \frac{y_1}{y_2} \\ x_4 &= \frac{y_1}{\sin \arctan \frac{y_1}{y_2}}. \end{align} Of course, you need to be sure that all the involved operations are allowed and separate the pathological cases (for instance, what happens when $$y_2=0$$?). Also, note that this is just one solution, whereas you can have infinitely many of them (can you see why?).