On a soccer tournament with $n\ge 3$ teams taking part, several matches are played in such a way that among any three teams, some two play a match.
$(a)$ If $n=7$, find the smallest number of matches that must be played.
$(b)$ Find the smallest number of matches in terms of $n$.
To solve this problem, we will use graph theory. We represent each team as a vertex in a graph, and each match between two teams as an edge between two vertices. The problem states that among any three teams, some two must play a match. This means that in the graph, there should be no set of three vertices (a triangle) where all three edges are missing. 

This is a well-known problem in extremal graph theory, often related to Turán's theorem. Turán's theorem gives us the maximum number of edges in a graph that does not contain a complete subgraph \( K_r \) (a set of \( r \) vertices all connected to each other).

### Part (a): \( n = 7 \)

1. **Graph Representation**:
   - We represent the 7 teams as vertices of a graph.
   - We need to ensure that among any three vertices, at least one edge exists.

2. **Turán's Theorem Application**:
   - For \( n = 7 \) and \( r = 3 \), Turán's theorem tells us that the maximum number of edges in a graph with 7 vertices that does not contain a \( K_3 \) (triangle) is given by \( T(7, 2) \), where \( T(n, r-1) \) is the Turán graph.
   - The number of edges in \( T(7, 2) \) is \( \left\lfloor \frac{7^2}{4} \right\rfloor = \left\lfloor \frac{49}{4} \right\rfloor = 12 \).

3. **Minimum Number of Matches**:
   - The total number of possible matches (edges) in a complete graph \( K_7 \) is \( \binom{7}{2} = 21 \).
   - The minimum number of matches required is the total number of edges minus the maximum number of edges that can be missing without violating the condition.
   - Therefore, the minimum number of matches is \( 21 - 12 = 9 \).

### Part (b): General \( n \)

1. **Graph Representation**:
   - We represent the \( n \) teams as vertices of a graph.
   - We need to ensure that among any three vertices, at least one edge exists.

2. **Turán's Theorem Application**:
   - For general \( n \) and \( r = 3 \), Turán's theorem tells us that the maximum number of edges in a graph with \( n \) vertices that does not contain a \( K_3 \) (triangle) is given by \( T(n, 2) \).
   - The number of edges in \( T(n, 2) \) is \( \left\lfloor \frac{n^2}{4} \right\rfloor \).

3. **Minimum Number of Matches**:
   - The total number of possible matches (edges) in a complete graph \( K_n \) is \( \binom{n}{2} = \frac{n(n-1)}{2} \).
   - The minimum number of matches required is the total number of edges minus the maximum number of edges that can be missing without violating the condition.
   - Therefore, the minimum number of matches is \( \frac{n(n-1)}{2} - \left\lfloor \frac{n^2}{4} \right\rfloor \).

Conclusion:
\[
\boxed{\frac{n(n-1)}{2} - \left\lfloor \frac{n^2}{4} \right\rfloor}
\]