# Hiking equation in python returns wrong results

Question asked by Alesinar on Jul 30, 2014
Latest reply on Aug 4, 2014 by Alesinar

Hi,

I've been trying to implement Tobler's hiking equation in script. The equation goes:

$W=6e^{\displaystyle-3.5\left\vert\frac{dh}{dx}+0.05\right\vert}$

$\frac{dh}{dx}=S=\tan\Theta$

Where:

W is walking speed,

S  is slope in degrees.

The list of slopes is:

k7=[-1.0312126698879267, 1.1457628381751035, -3.890124404061796, -0.6875278121450912, 0.0, -1.7820676357665195, -1.0532676344873988, 1.7010978323487986]


And my code is:

    for f in k7:
tob=6*math.expm1(-3.5*abs(f+0.05))
k8.append(tob)


Which should be right, but the results are:

k8=[-5.80650137556095, -5.908682283616555, -5.999991269395487, -5.355698099597122, -0.963257875384756, -5.986024888143845, -5.8208760494265395, -5.986925387994366]


First, they are negative and they shouldn't be, second, notice that the slopes are very similar and so should be the results but notice the fifth element of the results! When I tried this with math.exp I got something completly different and also totally wrong.

I know that this should be very simple but I cant figure it out.

Have I missed something in the equation or is there some trick that I should know about.

I would be really grateful for your help.

Aleš