I really need your help in math, I've solved this problem in several ways, but I'm not getting anywhere...
Given a straight line $x-3y-9=0$ and an ellipse $x^2/9 +y^2/4 = 1$, find the nearest and farthest points. As I understand it, the problem that I presented to you above can be solved using the Lagrange method (conditional extremes). However, the teacher did not like this option and she said that it was wrong, although the answer from the textbook is the same as mine.
I was told that I need to find the the farthest and closest distance using this $(x-X)^2+(y-Y)^2$, find derivatives, solve the system and find the determinants. I decided, but I didn't get an answer. Is it possible to solve it this way? If so, how? If not, how else is it possible? This is the progress of solving the task from my teacher.

I will be very grateful if you can help me!

Another method that is closer to what your teacher wants is as follows.
Let $(x,y)$ be on the line, then
$x - 3 y - 9 = 0 \tag{1} $
And let $(X, Y)$ be on the ellipse, then
$ \dfrac{X^2}{9} + \dfrac{Y^2}{4} = 1 \tag{2}$
The distance squared between $(x,y)$ and $(X, Y)$ is
$ f(x,y, X, Y) = (x - X)^2 + (y - Y)^2 \tag{3}$
Define the vector $V = (x, y, X, Y) $, then
$ f(V) = V^T A V \tag{4}$
where
$ A = \begin{bmatrix} 1 && 0 && -1 && 0 \\ 0 && 1 && 0 && -1 \\ -1 && 0 && 1 && 0 \\ 0 && -1 && 0 && 1 \end{bmatrix} \tag{5}$
Now define the Lagrange function as follows
$ g(V) = f(V) + \lambda_1 L(V) + \lambda_2 Q(V) \tag{6}$
where
$L(V) = a^T V + b \tag{7}$
with
$ a = \begin{bmatrix} 1 \\ -3 \\ 0 \\ 0 \end{bmatrix} \tag{8}$
and
$ b = -9 \tag{9} $
And,
$Q(V) = V^T B V - 1 \tag{10} $
where
$ B = \begin{bmatrix} 0 && 0 && 0 && 0 \\ 0 && 0 && 0 && 0 \\ 0 && 0 && \dfrac{1}{9} && 0 \\ 0 && 0 && 0 && \dfrac{1}{4} \end{bmatrix} \tag{11} $
The gradient vector of $g(V)$ is
$ \nabla_V g = 2 A V + \lambda_1 a + 2 \lambda_2 B V = \mathbf{0} \tag{12}$
In addition, we have
$ \nabla_{\lambda_1} g = a^T V + b = 0 \tag{13}$
And
$ \nabla_{\lambda_2} g = V^T B V - 1 = 0 \tag{14}$
Note that $A$ is not invertible. Define $u_1 = [1, 0, 1, 0]^T$ and $u_2 = [0,1,0,1]^T$ Then
$ u_1^T A = \mathbf{0} $ and $u_2^T A = \mathbf{0} $
Therefore, pre-multiplying $(12)$ by $u_1^T$ and $u_2^T$ gives us the following two equations:
$ \lambda_1 + \lambda_2 [0, 0, \dfrac{1}{9}, 0 ] V = 0 \tag{15} $
$ -3 \lambda_1 + \lambda_2 [ 0, 0, 0, \frac{1}{4} ] V = 0 \tag{16}$
Furthermore, if we pre-multiply equation $(12)$ by $e_1^T = [1, 0, 0, 0]$, we would get
$ 2 [1, 0, -1, 0] V + \lambda_1 = 0 \tag{17}$
And pre-multiplying $(12)$ by $e_2^T = [0, 1, 0, 0]$, we would get
$ 2 [0, 1, 0, -1] V - 3 \lambda_1 = 0 \tag{18}$
Combining $(15)-(16)$ by eliminating $\lambda_1$ and using the fact that $\lambda_2 \ne 0 $, we get
$ [ 0 , 0, \dfrac{1}{3}, \dfrac{1}{4} ] V = 0 \tag{19} $
Similarly, eliminating $\lambda_1$ from equations $(17)-(18)$, gives us
$ [3, 1, -3, -1] V = 0 \tag{20} $
So now we have the following system of equations, repeated below for clarity
$ a^T V + b = 0 \tag{21}$
$ [ 0 , 0, \dfrac{1}{3}, \dfrac{1}{4} ] V = 0 \tag{22} $
$ [3, 1, -3, -1] V = 0 \tag{23} $
$ V^T B V - 1 = 0 \tag{24}$
Which is a system of $4$ equations, three of which are linear and $1$ nonlinear (quadratic), in the four unknown entries of $V$.
Equations $(21)-(22)-(23)$ give us the following linear system
$\begin{bmatrix} 1 && - 3 && 0 && 0 \\ 0 && 0 && 4 && 3 \\ 3 && 1 && -3 && -1 \end{bmatrix} \begin{bmatrix} x \\ y \\ X \\ Y \end{bmatrix} = \begin{bmatrix} 9 \\ 0 \\ 0 \end{bmatrix} \tag{25}$
Its solution is
$ V = \begin{bmatrix} x \\ y \\ X \\ Y \end{bmatrix} = \begin{bmatrix} 0.9 \\ -2.7 \\ 0 \\ 0 \end{bmatrix} + t \begin{bmatrix} - 3 \\ - 1 \\ - 6 \\ 8 \end{bmatrix}\tag{26} $
To determine the parameter $t$, we substitute solution $(26)$ into the quadratic equation $(24)$.
Let $u = [0.9, -2.7, 0, 0]^T $ and $v = [-3, -1, -6, 8] $
Then
$(u + t v)^T B (u + t v) - 1 = 0 \tag{27}$
So that
$ (v^T B v) \ t^2 + 2 (u^T B v) \ t + (u^T B u - 1) = 0 $
This can be solved for $t$, using the quadratic formula, the results are,
$ t_1 = - 0.223606798 $ and $ t_2 = 0.223606798 $
Substituting these in $(26)$ gives two sets of corresponding coordinates $V$ that correspond to the minimum distance and the maximum distance.
For $t_1$ we have
$ V_1 = \begin{bmatrix} 1.570820393 \\ -2.476393202 \\ 1.341640786 \\ -1.788854382 \end{bmatrix} $
And for $t_2$ we have
$ V_2 = \begin{bmatrix} 0.229179607 \\ -2.923606798 \\ -1.341640786 \\ 1.788854382 \end{bmatrix} $
The value of the squared distance function is given by equation $(3)$, so that
$f(V_1) = 0.525232922 $
$ f(V_2) = 24.67476708 $
So $V_1$ corresponds to the minimum distance, and $V_2$ corresponds to the maximum distance.
The ellipse and the line, together with the location of the minimum and maximum distances are shown below