Given the formula $$v_a = p\left(\frac{\left(1+\frac{r}{n}\right) ^{nt}-1}{\frac{r}{n}}\right)$$
for the value $v_a$ of an account growing at a periodic rate $r$ with a regular deposit $p$ compounded $n$ times per period after $t$ periods, and the future value formula $$v_p = p\left(1+\frac{r}{n}\right) ^{nt}$$
where $p$ is the original value, $r$ is the periodic rate, $n$ is the number of times the value is compounded per period, and $t$ is the number of periods, how does one account for an increasing value for $p$ in $v_a$?
Example:
Jane invests 10% of her income in a 401k each year from the time she starts working at age 22 to the time she retires at age 62. She receives an annual income of $40,000 during her first year of employment. Each year, Jane receives a 5% raise in pay. She gets an average annual 7% interest rate on her retirement account (which is compounded monthly) over the span of her career. How much is in her account when she retires?
Strategy using the mean value of $p$ over the career in $v_a$:
Recall the average value of a function $f(x)$ over the interval $a \le x \le b$ is $\frac{1}{b-a} \int_{a}^{b} f(x) dx $, so the average value of Jane's annual 10% salary savings over her career is $$ \frac{1}{40}\int_{0}^{40}v_p(t)dt \\ \frac{1}{40} \int_{0}^{40} 4000*\left(1.05\right)^{t}dt = \frac{4000}{40}\int_{0}^{40}1.05^tdt\\ =100 \left(\left(\frac{1.05^{40}}{ln(1.05)}\right) - \left(\frac{1}{ln(1.05)}\right)\right)\\ = \$12,379.52$$ leading to a final account value of $$v_a = 12379.52\left(\frac{\left(1+\frac{.07}{12}\right) ^{12*40}-1}{\frac{.07}{12}}\right)\\ = \$32,493,930$$
Problems with the strategy:
This number seems too high because it assumes that for each year of her career, Jane earned compounded interest on \$12,379.52 of savings. That means for 39 years, she's compounding interest on \$12,379.52 - \$4,000 = \$8,379.52 excess principle.
However, during the second half of her career, she saves more principle than the average amount over her career, which also compounds while she continues to work. I can't prove to myself that the extra compounded interest each year prior to when the annual savings meets the average value (during the first half of her career) directly offsets the increased principle saved each year above the average savings (during the second half of her career).
I can set up the problem as the sum of a finite series, but I'm hoping for a more elegant analytical solution. Is the first strategy correct? If not, does an accurate analytical solution exist?