You can't. At least, not in any accurate way. The reason being that you have too many variables. Each variable adds a significant amount of error due to inaccuracies in measurement to your calculation. This might be a nice math problem, but as a physics problem, it has little application to the real world. My WAG is that the error in your calculation would probably exceed 50%.
If you want to determine fuel consumption, try just accurately measuring how much fuel is being consumed at any given moment in time. Your engine's fuel pump will "know" this information based on how hard it needs to work. It's a pretty trivial task to convert this information into something usable if you're in the process of designing a car's computer, which is why this feature is included in many newer cars.
As for the math that would give you a "miles per gallon" number, it would go like this:
For argument's sake, consumption rate R is measured by the fuel pump in ml/second. For the time being, let's measure speed (V) in metric as well, since that too is being measured accurately. Speed needs to be reduced to meters/second to match the fuel pump's consumption rate figures, allowing them to cancel out. The amount of fuel used over any distance would be:
Consumption = R / V
and Consumption would be measured in millilitres/meter. Multiply by 1000 for litres/km.
You're right that the reduction in velocity takes some time. Let me spell out in more words/equations what you seem to already understand!
You're demanding that the power, $P=F_{\text{engine}}v$ is constant. You also have some $F_{\text{friction}}$, the force due to rolling friction, and $F_{\text{gravity}}$, the force pulling the car backwards along its axis of motion due to gravity.
From free body diagrams, $F_{\text{friction}}=\mu g M \cos(\theta)$, where $\theta$ is the angle of the slope, $\mu$ is the coefficient of rolling friction, and $gM$ is the normal force due to gravity. The force of gravity along the direction of motion is $F_{\text{gravity}}=g M \sin(\theta)$.
If the car's velocity is in equilibrium, then we have:
\begin{align*}
0&=F_{\text{engine}}-F_{\text{friction}}-F_{\text{gravity}}\\
&=\frac{P}{v}-\mu g M\cos(\theta)-g M\sin(\theta)
\end{align*}
So
$$v=\frac{P}{g M(\mu\cos(\theta)+\sin(\theta))}$$
This $v$ is the equilibrium velocity. If $\theta=0$ this just gives the velocity needed to push a block at constant power. If $\theta=\pi/2$ this just gives the velocity needed to lift a block at constant power. For a low coefficient of rolling friction, pushing is easier than lifting, and the higher theta is the lower the velocity for constant power is.
I think you've grasped all this intuitively in fewer words and equations! Obviously if someone is going straight and starts going up a hill without stepping more on the gas pedal, they're going to slow down over time.
There are a lot of assumptions made, however. For example, the relation between $F_{\text{engine}}$ and the power $P$ is probably wrong. You would expect the force that an engine delivers to depend on the velocity, the load placed on it, and all sorts of other things. My point is: this is kind of a weird constraint to put on an engine (for example, it breaks down when the car starts from a standstill and $v=0$). If you're working for BMW then you need a better model, but it suffices to us. We have a description showing that the car has to slow down.
Unfortunately it's harder to figure out how the slow-down happens. There is in fact an unbalanced force, so we have to start plugging stuff into Newton's law $F=ma$. We have to worry about the equation
$$ma=\frac{P}{v}-\mu g M\cos(\theta)-g M\sin(\theta)$$
which is an ugly, ugly thing. It's so ugly because it's nonlinear. The $v$ on the bottom completely screws up any non-calculus based methods you've learned so far (You wind up with an ordinary differential equation of the form $y''(t)=A/y'(t)+B$, where $y''$ is acceleration and $y'$ is velocity). It's easier to resort to numerics to solve it.
Let's look at the following situation: We have a 1 metric ton car which is being pulled by 1000 watts of power (this is a bit over 1 horsepower). It goes on flat ground at constant velocity for a bit, then goes up a three degree slope. That is: $\mu=0.01$, $g=9.81 \text{m}/\text{s}^2$, $M=1000\text{kg}$, $P=1000\text{watts}$, $\theta=\pi/60$. The graph of velocity over time looks as follows:
It starts at about ten meters per second and travels along at constant velocity. When it hits the slope, it takes about twenty seconds to slow all the way down to a bit less than two meters per second.
The graph was generated with the following Mathematica code. (Note: HeavisideTheta[t] returns 0 if t<0 and 1 if t>0)
theta=Pi/60; mu=0.01; m=1000; g=9.81; power=1000; t0=-50;tend=50;
gravityForce[t_]=g m Sin[theta] HeavisideTheta[t];
rollingFriction[t_]=mu g m-(1-Cos[theta])mu g m HeavisideTheta[t];
engineForce[t_]=power/ x'[t];
soln=NDSolve[{m x''[t]==engineForce[t]-rollingFriction[t]-gravityForce[t],x[t0]==0,x'[t0]==power/(g m mu)},{x[t],x'[t]},{t,t0,tend}];
Plot[x'[t]/.soln,{t,t0,tend},PlotLabel->"Car Velocity over time",AxesLabel->{"t (s)","v (m/s)"}]
Best Answer
They are stating that as part of the question, not stating that it's necessarily true. You often see things like "ignoring air resistance", a "frictionless plane" or "massless spring" as part of questions to allow a simple analytical answer.
in reality for a car moving at 40 m/s air resistance is likely to be the major source of drag and this is proportional to velocity^2, but this makes the resulting equations trickier