Solving system of equations with R Suppose I have the following function :
$f(x,y,z,a)= \cos(ax) + 12y^2 - 9az$ 
and I want to solve the following syste of equations.
$ f(x,y,z,1)= 10 $, 
$f(x,y,z,5)= 7 $, 
and 
$f(x,y,z,-3)= 17 $.
These are equivalent to 
$\cos(x) + 12 y^2 - 9 z(1) = 10$, 
$ \cos(5x) + 12y^2 - 9 z(5) = 7 $,
and $ \cos(-3x) + 12y^2 +27z = 17 $.
How do I solve these equations for $x$, $y$,  and $z$? I would like to solve these equations, if possible, using R or any other computer tools.

This is a partial answer; I can't give actual code, since I'm not familiar with R.

The standard way to solve this type of problem is to reformulate it as a nonlinear root-finding (or nonlinear optimization) problem and then use existing software or packages.


*

*First, write your equations as follows: \begin{align}
\cos x + 12 y^2 - 9 z - 10 &= 0 \\
\cos 5 x + 12 y^2 - 45 z - 7 &= 0 \\
\cos 3 x + 12 y^2 + 27 z - 17 &= 0
\end{align} (in the last equation we have used the even symmetry of $\cos$: $\cos(-x) = \cos x$). 

*Next, observe that this the above equations are equivalent to the following problem: Find the root of the nonlinear function $\textbf{F} : \mathbb{R}^3 \to \mathbb{R}^3$: \begin{equation}
\textbf{F}(\textbf{x}) = \begin{bmatrix} \cos x + 12 y^2 - 9 z - 10 = 0 \\
\cos 5 x + 12 y^2 - 45 z - 7 = 0 \\
\cos 3 x + 12 y^2 + 27 z - 17 = 0 \end{bmatrix}, \end{equation} where \begin{equation} \textbf{x} = \begin{bmatrix} x \\ y \\ z \end{bmatrix}; \end{equation} that is, solve the equation $$ \textbf{F}(\textbf{x}) = \textbf{0} \tag{1} $$ for $\textbf{x} \in \mathbb{R}^3$.


Unfortunately it is not immediately clear if this problem has a solution. Moreover, if it does, it is not clear precisely how many solutions it has. Nonetheless, we can proceed using a couple of packages for R that are available on CRAN: rootSolve and ucminf.
I would suggest first using rootSolve: it is a nonlinear root-finding package, and will try to solve Equation (1) assuming that a solution exists. It will require an initial guess; ideally it would be close to what you think is a solution, but to get started, feel free to try $x = 0, y = 0, z = 0$ or $x = 1, y = 1, z = 1$ or even $x, y, z =$ random numbers. When your script is running and returning output, you should test that your solution is correct: put the output back into the function $\textbf{F}(\textbf{x})$ and test that it is $\approx \textbf{0}$.
If it fails this test, then you might need to use a different initial guess, or just cut your losses and use ucminf: this package is a nonlinear optimization package. It does not assume that your function has an exact solution; instead, it tries to find $\textbf{x} \in \mathbb{R}^3$ such that $\left\| \textbf{F}(\textbf{x}) \right\|$ is minimized. If it happens that the problem has a solution, but for some reason rootSolve was not able to find it, then this nonlinear optimization problem is equivalent; otherwise it will simply be an optimal "solution".
Again, let me stress that nonlinear problems may not even have a solution, or may have several solutions, even though the output of the functions will indicate only one solution. Moreover, the output should always checked. Solving nonlinear systems of equations is not easy. Hopefully someone with more experience in R can comment or make a post on how to actually implement this.
