If $x_0=x_1=1$, and for $n\geq1$

$x_{n+1}=\frac{x_n^2}{x_{n-1}+2x_n}$,

find a formula for $x_n$ as a function of $n$.
1. Given the recurrence relation \( x_0 = x_1 = 1 \) and for \( n \geq 1 \), \( x_{n+1} = \frac{x_n^2}{x_{n-1} + 2x_n} \), we need to find a formula for \( x_n \) as a function of \( n \).

2. Define \( y_n = \frac{x_{n-1}}{x_n} \) for \( n \geq 1 \). We start with \( y_1 = \frac{x_0}{x_1} = 1 \).

3. Using the recurrence relation, we can express \( y_{n+1} \) in terms of \( y_n \):
   \[
   x_{n+1} = \frac{x_n^2}{x_{n-1} + 2x_n}
   \]
   Dividing both sides by \( x_n \), we get:
   \[
   \frac{x_{n+1}}{x_n} = \frac{x_n}{x_{n-1} + 2x_n}
   \]
   Taking the reciprocal, we have:
   \[
   \frac{x_n}{x_{n+1}} = \frac{x_{n-1} + 2x_n}{x_n} = \frac{x_{n-1}}{x_n} + 2 = y_n + 2
   \]
   Therefore:
   \[
   y_{n+1} = y_n + 2
   \]

4. Since \( y_1 = 1 \) and \( y_{n+1} = y_n + 2 \), we can solve this recurrence relation:
   \[
   y_n = 1 + 2(n-1) = 2n - 1
   \]

5. Now, we know \( y_n = \frac{x_{n-1}}{x_n} = 2n - 1 \). This implies:
   \[
   x_{n-1} = (2n - 1) x_n
   \]

6. To find \( x_n \), we consider the product of \( y_1, y_2, \ldots, y_n \):
   \[
   y_1 y_2 \cdots y_n = (2 \cdot 1 - 1)(2 \cdot 2 - 1) \cdots (2n - 1) = (2n-1)!!
   \]
   where \( (2n-1)!! \) denotes the double factorial of \( (2n-1) \).

7. Since \( y_1 y_2 \cdots y_n = \frac{x_0}{x_n} \) and \( x_0 = 1 \), we have:
   \[
   (2n-1)!! = \frac{1}{x_n}
   \]
   Therefore:
   \[
   x_n = \frac{1}{(2n-1)!!}
   \]

The final answer is \( \boxed{ x_n = \frac{1}{(2n-1)!!} } \).