Okay, so I need to find the largest value of 'a' such that the graph of the given piecewise function intersects every horizontal line at least once. Let me start by understanding the problem step by step.

First, the function f(x) is defined as two different expressions depending on whether x is greater than or equal to 'a' or less than 'a'. The two cases are:
1. For x ≥ a: f(x) = a x²
2. For x < a: f(x) = a x + 2a

The question is asking for the largest 'a' such that every horizontal line y = k (where k is any real number) intersects the graph of f(x) at least once. In other words, for every k, there exists some x where f(x) = k.

So, my task is to determine the maximum value of 'a' for which this condition holds. Let's break this down.

First, let's recall what it means for a horizontal line to intersect the graph of a function. For a given k, there must be at least one x such that f(x) = k. Since the function is piecewise, I need to check both cases for each k and ensure that at least one solution exists in either the quadratic case or the linear case.

So, for a given k, we need to check:
1. If there's an x ≥ a such that a x² = k.
2. If there's an x < a such that a x + 2a = k.

If for every k, at least one of these equations has a solution, then the function intersects every horizontal line. The largest 'a' for which this is true is what we need.

Let me approach this by first considering the linear part. The linear function is f(x) = a x + 2a for x < a. Let's find the range of this linear function. Since x can be any real number less than 'a', we need to see what values of f(x) this can take.

The linear function f(x) = a x + 2a can be rewritten as f(x) = a(x + 2). The behavior of this linear function depends on the slope 'a'. If a > 0, the function is increasing, and as x approaches negative infinity, f(x) approaches negative infinity, and as x approaches 'a' from the left, f(x) approaches a(a + 2). If a < 0, the function is decreasing, and as x approaches negative infinity, f(x) approaches positive infinity, and as x approaches 'a' from the left, f(x) approaches a(a + 2). If a = 0, then f(x) = 0 for all x < 0, but since the function is defined piecewise with a quadratic for x ≥ a, which would also become 0, but that's a trivial case and likely not the maximum 'a' we're looking for.

Wait, but if a = 0, then both cases of the function become 0, which is a constant function. A constant function would only intersect horizontal lines at y=0, so it doesn't satisfy the condition of intersecting every horizontal line. So, a = 0 is out. Therefore, we need to consider a ≠ 0.

So, for a ≠ 0, the linear part's range is:

If a > 0: f(x) can take all values from negative infinity up to a(a + 2).

If a < 0: f(x) can take all values from positive infinity down to a(a + 2).

Now, the quadratic part is f(x) = a x² for x ≥ a. The behavior of this quadratic function depends on the coefficient 'a'. If a > 0, then the quadratic opens upwards, and its minimum value occurs at x = a. The value at x = a is f(a) = a*(a²) = a³. As x increases beyond a, the function goes to infinity. So, the range of the quadratic part is [a³, ∞).

If a < 0, the quadratic opens downward, and since x ≥ a (which for a < 0 is a negative number), the function will have a maximum at x = a. The value at x = a is a³. As x increases beyond a, the function decreases towards negative infinity. Therefore, the range of the quadratic part is (-∞, a³].

So, combining the two parts:

For a > 0:
- The linear part's range is (-∞, a(a + 2)].
- The quadratic part's range is [a³, ∞).
Thus, the total range of f(x) is the union of these two intervals: (-∞, a(a + 2)] ∪ [a³, ∞).

For the function to intersect every horizontal line, the union of these two ranges must cover all real numbers. That is, there should be no gaps between the two intervals. Therefore, the maximum of the linear part's upper bound must be greater than or equal to the minimum of the quadratic part's lower bound. In other words:

a(a + 2) ≥ a³

This inequality must hold for the union of the two intervals to cover all real numbers. Let's solve this inequality for a > 0.

First, expand the left side:

a² + 2a ≥ a³

Bring all terms to one side:

a³ - a² - 2a ≤ 0

Factor out an 'a':

a(a² - a - 2) ≤ 0

Factor the quadratic:

a(a - 2)(a + 1) ≤ 0

So, the critical points are a = -1, 0, 2. Since we're considering a > 0, we can ignore a = -1 and a = 0. The intervals to test are (0, 2) and (2, ∞).

For a in (0, 2), let's pick a = 1:

1(1 - 2)(1 + 1) = 1*(-1)(2) = -2 ≤ 0. So the inequality holds.

For a in (2, ∞), pick a = 3:

3(3 - 2)(3 + 1) = 3(1)(4) = 12 > 0. The inequality does not hold.

Therefore, for a > 0, the inequality a(a + 2) ≥ a³ holds when a ≤ 2. So the maximum a in this case is 2.

Now, let's check for a < 0.

If a < 0, the linear part's range is (positive infinity, a(a + 2)]. Wait, no. Wait, when a < 0, the linear function is f(x) = a x + 2a. Since a is negative, the slope is negative, so it's a decreasing function. As x approaches negative infinity, f(x) approaches positive infinity (because a x with a negative x is positive, multiplied by a negative a gives positive infinity). As x approaches 'a' from the left, f(x) approaches a(a + 2). So the range is (a(a + 2), ∞). Wait, but a(a + 2) when a is negative. Let me compute that.

Wait, when a is negative, the linear function f(x) = a x + 2a. As x approaches negative infinity, since a is negative, a x approaches positive infinity (negative times negative is positive), so a x + 2a approaches positive infinity. As x approaches 'a' from the left, x approaches 'a', so f(x) approaches a*a + 2a = a² + 2a. Since a is negative, a² is positive, and 2a is negative, so a² + 2a could be positive or negative depending on the value of a. For example, if a = -1, a² + 2a = 1 - 2 = -1. If a = -2, a² + 2a = 4 - 4 = 0. If a = -3, a² + 2a = 9 - 6 = 3.

So, the linear part's range is (a(a + 2), ∞). Now, the quadratic part for a < 0. The quadratic function is f(x) = a x² for x ≥ a. Since a < 0, the quadratic opens downward. The vertex of the parabola is at x = 0 (since the derivative is 2a x, set to zero gives x=0), but our domain is x ≥ a. Since a is negative, x is greater than or equal to a negative number. The maximum value of the quadratic occurs at the vertex x=0, which is f(0) = 0. But since x must be ≥ a, and a is negative, the maximum value on the domain x ≥ a is the larger of f(a) and f(0). Let's compute f(a) = a*(a²) = a³. Since a is negative, a³ is negative. And f(0) = 0. So the maximum value of the quadratic part is 0, and the function decreases to negative infinity as x increases beyond 0. Therefore, the range of the quadratic part is (-∞, 0].

Therefore, for a < 0:
- The linear part's range is (a(a + 2), ∞).
- The quadratic part's range is (-∞, 0].

The union of these two ranges is (-∞, 0] ∪ (a(a + 2), ∞). For the union to cover all real numbers, there must be no gap between 0 and a(a + 2). Therefore, 0 must be greater than or equal to a(a + 2). Wait, but a(a + 2) when a is negative. Let's compute a(a + 2):

For a < 0, let's see when a(a + 2) ≤ 0. Because if a(a + 2) ≤ 0, then the gap between 0 and a(a + 2) is zero or negative, meaning that the union would be all real numbers. Wait, let's think carefully.

The linear part's range is (a(a + 2), ∞). The quadratic part's range is (-∞, 0]. So, the union will be (-∞, 0] ∪ (a(a + 2), ∞). For this union to be all real numbers, the interval (a(a + 2), ∞) must start at a point less than or equal to 0. Because otherwise, there would be a gap between 0 and a(a + 2). So, to ensure that (a(a + 2), ∞) starts at or before 0, we need:

a(a + 2) ≤ 0

Solving this inequality for a < 0.

a(a + 2) ≤ 0

Multiply out: a² + 2a ≤ 0

Factor: a(a + 2) ≤ 0

The roots of the equation a(a + 2) = 0 are a = 0 and a = -2. The quadratic opens upwards, so the inequality a(a + 2) ≤ 0 holds when a is between -2 and 0. Therefore, for a in [-2, 0], the inequality holds. But since we are considering a < 0, the relevant interval is [-2, 0). However, since we are looking for the largest 'a' such that the condition holds, and in the previous case for a > 0, the maximum was 2. Now, for a < 0, the maximum a would be approaching 0 from the negative side, but the problem is that a must be the largest value. Wait, but in this case, the maximum a (closest to zero) in the negative direction would be approaching 0, but since we need to check if there's a specific maximum a, perhaps the maximum a in this case is 0, but 0 isn't allowed because then the function becomes constant. Wait, but in the a < 0 case, the maximum a (largest in the negative direction) that satisfies a(a + 2) ≤ 0 is a = -2. Because at a = -2, a(a + 2) = (-2)(0) = 0. So, if a = -2, then the linear part's range is (0, ∞), and the quadratic part's range is (-∞, 0]. Therefore, their union is all real numbers. Therefore, for a = -2, the union covers all real numbers. However, if a is less than -2, say a = -3, then a(a + 2) = (-3)(-1) = 3. Then the linear part's range is (3, ∞), and the quadratic part's range is (-∞, 0]. The union is (-∞, 0] ∪ (3, ∞), which leaves a gap between 0 and 3. Therefore, the function would not intersect every horizontal line (specifically, lines between 0 and 3 wouldn't be intersected). Therefore, for a < 0, the largest possible 'a' is -2. But this is a negative number, which is smaller than the 2 we found in the a > 0 case. Therefore, the maximum 'a' overall would be 2, since 2 > -2.

Wait, but the problem says "the largest value of a such that the graph of y = f(x) intersects every horizontal line at least once." So, between a > 0 and a < 0, the maximum a is 2. However, we need to check whether this is indeed the case, and also verify if there are any other constraints.

Wait, but let's make sure. For a = 2, let's check the ranges.

For a = 2, the linear part is f(x) = 2x + 4, defined for x < 2. The range of this linear function when x < 2 is:

Since a = 2 > 0, the linear function is increasing. As x approaches -∞, 2x + 4 approaches -∞. As x approaches 2 from the left, 2x + 4 approaches 8. So the range is (-∞, 8].

The quadratic part is f(x) = 2x² for x ≥ 2. The quadratic function opens upwards, with its vertex at x = 0 (but domain is x ≥ 2). At x = 2, f(2) = 2*(4) = 8. As x increases beyond 2, f(x) increases to infinity. So the range of the quadratic part is [8, ∞).

Therefore, the total range is (-∞, 8] ∪ [8, ∞) = all real numbers. Therefore, for a = 2, the function does intersect every horizontal line.

Now, let's check a slightly larger than 2, say a = 3. Then, the linear part is f(x) = 3x + 6 for x < 3. The range is (-∞, 3*3 + 6) = (-∞, 15]. The quadratic part is f(x) = 3x² for x ≥ 3. At x = 3, f(3) = 27, and as x increases, f(x) goes to infinity. So the quadratic part's range is [27, ∞). Therefore, the total range is (-∞, 15] ∪ [27, ∞), which leaves a gap between 15 and 27. Therefore, horizontal lines y = 16, for example, would not be intersected. Thus, a = 3 doesn't satisfy the condition.

Therefore, a cannot be larger than 2. So 2 is indeed the maximum.

But let's check a = 2.5 as another test. Then the linear part's upper bound is 2.5*(2.5 + 2) = 2.5*4.5 = 11.25, and the quadratic part starts at 2.5*(2.5)^2 = 2.5*6.25 = 15.625. So the ranges are (-∞, 11.25] and [15.625, ∞). There's a gap between 11.25 and 15.625, so a = 2.5 is invalid. Therefore, 2 is indeed the maximum.

But let's also check for a just below 2, say a = 1.9. Then, the linear part's upper bound is 1.9*(1.9 + 2) = 1.9*3.9 = 7.41. The quadratic part's minimum is 1.9*(1.9)^2 = 1.9*3.61 ≈ 6.859. Wait, but 6.859 is less than 7.41. So the quadratic part's minimum is ≈6.859, and the linear part's upper bound is 7.41. Therefore, the ranges would be (-∞, 7.41] and [6.859, ∞). There's a small overlap here? Wait, no. Wait, the quadratic part's range is [6.859, ∞), and the linear part's range is (-∞, 7.41]. So the union is (-∞, 7.41] ∪ [6.859, ∞). But since 6.859 < 7.41, the union is (-∞, ∞). Wait, no, that's not correct. Wait, the union would actually be (-∞, 7.41] ∪ [6.859, ∞) which is all real numbers because the interval [6.859, ∞) starts before 7.41. Wait, but [6.859, ∞) starts at 6.859, and (-∞, 7.41] ends at 7.41. Since 6.859 < 7.41, the union would be (-∞, ∞). Therefore, for a = 1.9, the union covers all real numbers. Therefore, a can be less than 2, but the maximum a is 2. So, when a = 2, the linear part's upper bound is exactly equal to the quadratic part's lower bound. Therefore, the union is all real numbers. For a > 2, the upper bound of the linear part is less than the lower bound of the quadratic part, creating a gap. Therefore, a = 2 is indeed the maximum.

But let's confirm this by checking a = 2. When a = 2, the linear part's upper bound is 8, and the quadratic part's lower bound is 8. Therefore, the union of ranges is all real numbers. For a just above 2, say 2.1, the linear part's upper bound would be 2.1*(2.1 + 2) = 2.1*4.1 = 8.61, and the quadratic part's lower bound is 2.1*(2.1)^2 = 2.1*4.41 = 9.261. Then, the union would be (-∞, 8.61] ∪ [9.261, ∞), leaving a gap between 8.61 and 9.261. Therefore, a = 2.1 is invalid.

Therefore, the maximum a is indeed 2.

But let's check another angle. Suppose we take a = 2. Then, the quadratic part starts at x = 2 with f(2) = 2*(2)^2 = 8. The linear part ends at x approaching 2 from the left with f(2-) = 2*(2) + 4 = 8. Therefore, the function is continuous at x = 2? Wait, no. Wait, the function is defined as f(x) = 2x + 4 for x < 2, and f(x) = 2x² for x ≥ 2. Therefore, at x = 2, the left limit is 2*2 + 4 = 8, and the right limit is 2*(2)^2 = 8. Therefore, the function is continuous at x = 2. Therefore, there is no gap at x = 2, which is good. Therefore, the function is continuous everywhere, which might have implications for the range.

Wait, but continuity might not directly affect the range, but in this case, it's important because if there's a jump discontinuity, the function might skip some values. But in this case, since the function is continuous at x = 2, there's no jump. Therefore, the ranges of the two pieces overlap at the point x = 2, f(x) = 8, so the union is indeed all real numbers.

Therefore, after all this analysis, the largest value of a is 2.

But let me check if there are any other possible issues. For example, suppose a is 2, then the function is continuous everywhere, and the ranges of the two pieces meet exactly at 8, so there's no gap. Therefore, every horizontal line y = k will intersect the graph. For k = 8, the intersection is at x = 2. For k > 8, it's on the quadratic part, and for k < 8, it's on the linear part. Therefore, all horizontal lines are covered.

Therefore, the answer should be 2.

**Final Answer**
The largest value of \( a \) is \boxed{2}.
Therefore, the largest value of $a$ such that the graph of $y=f(x)$ intersects every horizontal line at least once is $\boxed{2}$.
</think>