Im trying to optimize the equation if $x = x( \theta)$ is a function of $\theta$ and
$$ \frac{9.8}{800 \cos^2 \theta } x^2 - \tan \theta x + 13.5 = 0 $$
I know I need to apply implicit differentiation to obtain the value of $\theta$ that maximizes $x$. Is there a built in funcion in MATLAB to perform such a task?
To get nicer coefficients, let us rewrite the equation as $$\frac{49 \sec ^2(\theta )}{4000}x^2- \tan (\theta )x+\frac{27}{2}=0$$ Solving the quadratic gives two roots which, after a few trigonometric simplifications, write $$x_{1,2}=\frac{20}{49} \left(50 \sin (2 \theta )\pm \sqrt{5}\cos 2(\theta ) \sqrt{-1000 \cos (2 \theta ) -323 }\right)$$ As you can see, there are areas where $$1000 \cos (2 \theta ) +323>0$$ would make problems (leading to complex solutions).
Looking at the plot, you will easily identify that $x_2$ is the solution giving a maximum close to $\theta=1$.
Computing the derivative $$\frac{dx_2}{d\theta}=\frac{10}{49} \left(200 \cos (2 \theta )+\frac{\sqrt{5} (1323 \sin (2 \theta )+1000 \sin (4 \theta ))}{\cos(\theta)\sqrt{-1000 \cos (2 \theta )-323}}\right)$$ Cancelling this derivative is not the simplest problem and I would suggest to use Newton method starting with $\theta_0=1$. Letting you the please of computing the next derivative, Newton iterates would be $$\left( \begin{array}{cc} n & \theta_n \\ 0 & 1 \\ 1 & 1.030651783 \\ 2 & 1.042903695 \\ 3 & 1.043856413 \\ 4 & 1.043861059 \end{array} \right)$$ The second derivative (what you have since using Newton method) will confirm that this is a maximum. Evaluating will give $x_{max}\approx 23.7472$.