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

1k Views Asked by At

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$.

1

There are 1 best solutions below

5
On BEST ANSWER

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$. Newton Delta is 2

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