Two halls 6 and 9 meters perpendicularly intersect. Find the length of the longest straight bar to be passed horizontally from one aisle to another by a corner without deformation.

and this is my try:

How to find the equation to maximize in this problem.Please.
We use your diagram. We calculate the length of the diagonal when the angle at the bottom is $\theta$.
The part from the bottom to the obstructive corner is $\frac{9}{\sin \theta}$, and the rest is $\frac{6}{\cos\theta}$. We want to minimize $f(\theta)$, where $$f(\theta)=\frac{9}{\sin\theta}+\frac{6}{\cos\theta}.$$ To find the minimum, use the usual tools. We have $$f'(\theta)=-\frac{9\cos\theta}{\sin^2\theta}+\frac{6\sin\theta}{\cos^2\theta}.$$ Set this equal to $0$. You will find that $\tan^3\theta$ has to be a certain quantity.
Remark: A rectangular coordinates approach along the lines you are pursuing will also work, albeit a little less smoothly. I cannot make detailed comments, the work is difficult to read.