# Finding the slope for Euler's method of evaulating differential equations

The change in the belocity of a body falling at a relatively slow speed over a short distance is given by $\frac{\mathrm{d}v}{\mathrm{d}t}= g - kv$, where $g$ is the acceleration due to gravity and $k$ is a constant. Let $g = 9.8$m/sec$^2$, $k = 0.02$, $\Delta t = 2$, and $v_0 = 0$.

Write a formula for velocity using Euler's Method.

I know that Euler's method is: (new $y$ value) = (old $y$ value) + (slope of curve at old pt)*(change in x)

So for this it would be $v_1 = v_0 + \left(g-kv_0 \right)\Delta t$ ?????

I don't trust my slope of $y$.

-

Let us rewrite your system. You have \begin{align} \dot v = g -kv = f(v) \end{align} Now Euler's (explicit) method reads \begin{align} v_{i+1} =v_i + h f(v_i) = v_i +\Delta tg -\Delta tkv_i = (1-\Delta tk)v_i +\Delta tg \end{align} And this is ecactly, what you wrote for $i=0$.

Some extra candy: Note, that there is also an implicit Euler method $v_{i+1} = v_{i}+hf(v_{i+1})$ which is implicit and therefore more stable. I wrote a quick Matlab code for your problem, combining explicit and implicit Euler and the analytical solution. I really encourage you, to take a different choice for $\Delta t$.

function newtonVelocity

close all

figure
y=[0];
k = 0.02;
Dt=1;
g = 9.81;

for i=1:100;
y = [y,y(end)*(1-Dt*k)+Dt*g];
end
plot(y)
title('Euler method');
xlabel('Time');ylabel('Velocity');
grid on

y=[0];
for i=1:100;
y = [y,y(end)/(1+Dt*k)+Dt/(1+Dt*k)*g];
end
hold on
plot(y,'*r');
xlabel('Time');ylabel('Velocity');
grid on

t = 0:100;
z= (1-exp(-k*t))*g/k; % this is the analytical solution
plot(z,'-g');
legend('Explicit','Implicit','Analytical Solution');

end


Here is a plot for $\Delta t = 2$.

And here for $\Delta t=1$, which is still large.

-
Just because I haven't seen that notation before, does $\dot v$ mean $v^{\prime}$? –  yiyi Feb 26 '13 at 8:37
@MaoYiyi yes. In phycis one often writes $\dot f$ instead of $f'$ to emphasize that it is a derivative with respect to time. –  sonystarmap Feb 26 '13 at 8:38
So am I correct? –  yiyi Feb 26 '13 at 8:45
But only if it is a function of $t$. So for $f=f(x)$ you write $f'(x)$, but for $g=g(t)$ you could write $\dot g(t)$. –  sonystarmap Feb 26 '13 at 8:46
Yes you are correct! (In the comment above, I haven't read your reply to my first comment) –  sonystarmap Feb 26 '13 at 8:46