<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Hiking equation in python returns wrong results in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308714#M24025</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't see the syntax option in the reply window, just the original post.&amp;nbsp; In a reply window, you need to click the "Use advanced editor" link in the upper right and then you will get the syntax highlight option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 31 Jul 2014 23:44:14 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2014-07-31T23:44:14Z</dc:date>
    <item>
      <title>Hiking equation in python returns wrong results</title>
      <link>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308710#M24021</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've been trying to implement Tobler's hiking equation in script. The equation goes:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="W=6e^{\displaystyle-3.5\left\vert\frac{dh}{dx}+0.05\right\vert}" class="tex jive-image mwe-math-fallback-png-inline" src="http://upload.wikimedia.org/math/f/1/d/f1d448beef526fad1300c8528e0eb8d4.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="\frac{dh}{dx}=S=\tan\Theta" class="tex jive-image mwe-math-fallback-png-inline" src="http://upload.wikimedia.org/math/2/3/6/2360141adf15d59cf49e6b74dd78e167.png" /&gt;&lt;/P&gt;&lt;P&gt;Where:&lt;/P&gt;&lt;P&gt;W is walking speed,&lt;/P&gt;&lt;P&gt;S&amp;nbsp; is slope in degrees.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The list of slopes is:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14067342643751442 jive_text_macro" jivemacro_uid="_14067342643751442"&gt;
&lt;P&gt;k7=[-1.0312126698879267, 1.1457628381751035, -3.890124404061796, -0.6875278121450912, 0.0, -1.7820676357665195, -1.0532676344873988, 1.7010978323487986]&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And my code is:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14067342817772738" jivemacro_uid="_14067342817772738"&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for f in k7:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tob=6*math.expm1(-3.5*abs(f+0.05))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; k8.append(tob)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which should be right, but the results are:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14067343010916459 jive_text_macro" jivemacro_uid="_14067343010916459"&gt;
&lt;P&gt;k8=[-5.80650137556095, -5.908682283616555, -5.999991269395487, -5.355698099597122, -0.963257875384756, -5.986024888143845, -5.8208760494265395, -5.986925387994366]&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know that this should be very simple but I cant figure it out.&lt;/P&gt;&lt;P&gt;Have I missed something in the equation or is there some trick that I should know about.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would be really grateful for your help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aleš&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jul 2014 15:32:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308710#M24021</guid>
      <dc:creator>GrljAles</dc:creator>
      <dc:date>2014-07-30T15:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Hiking equation in python returns wrong results</title>
      <link>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308711#M24022</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You shouldn't be plugging in the slopes into the function. The equation says that it takes the tangent of the slope. Also, I would doubt that slope should be in degrees if it is going into a trig function. In any case, python uses radians so you'll need to convert to radians to use the tangent function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;6 * math.exp(-3.5 * abs(math.tan(math.radians(degrees)) + 0.05))) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For a sanity check, put in a values of the 5th value (0) and the 1st value:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def hike(degrees):&lt;/P&gt;&lt;P&gt;&amp;nbsp; return 6 * math.exp(-3.5 * abs(math.tan(math.radians(degrees)) + 0.05))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hike(0)&lt;/P&gt;&lt;P&gt;5.036742124615245&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hike(-1.0312126698879267)&lt;/P&gt;&lt;P&gt;5.3642655450021355&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both of which checks yield results around 5 km/h which is expected given the input of 0 and a near 0&amp;nbsp; slope.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully this helps!&lt;/P&gt;&lt;P&gt;Could you tell me - how is it you format code on the new forums?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jul 2014 17:52:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308711#M24022</guid>
      <dc:creator>DouglasSands</dc:creator>
      <dc:date>2014-07-30T17:52:10Z</dc:date>
    </item>
    <item>
      <title>Re: Hiking equation in python returns wrong results</title>
      <link>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308712#M24023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Douglas,,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for advice, it solved my problem! I knew there had to be some simple solution but I'm new to this stuff.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;About formatting the code:There is option for formatting in different styles when you are posting the question, however I don't see it here in the reply window.&lt;/P&gt;&lt;P&gt;When posting question it is under the quotation mark as in image:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Screenshot 2014-07-30 20.52.18.png" class="jive-image image-1" src="/legacyfs/online/2755_Screenshot 2014-07-30 20.52.18.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried copying from notepad++ via plugin nppExport but it doesn't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you again!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aleš&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jul 2014 18:59:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308712#M24023</guid>
      <dc:creator>GrljAles</dc:creator>
      <dc:date>2014-07-30T18:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: Hiking equation in python returns wrong results</title>
      <link>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308713#M24024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm happy to help. Thanks for pointing that out! I hadn't been able to figure it out till now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Jul 2014 13:44:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308713#M24024</guid>
      <dc:creator>DouglasSands</dc:creator>
      <dc:date>2014-07-31T13:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: Hiking equation in python returns wrong results</title>
      <link>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308714#M24025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't see the syntax option in the reply window, just the original post.&amp;nbsp; In a reply window, you need to click the "Use advanced editor" link in the upper right and then you will get the syntax highlight option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 31 Jul 2014 23:44:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308714#M24025</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2014-07-31T23:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Hiking equation in python returns wrong results</title>
      <link>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308715#M24026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The difficulty of finding the code formatter is being discussed in this thread:&amp;nbsp; &lt;A _jive_internal="true" href="https://community.esri.com/message/390783#390783" title="https://community.esri.com/message/390783#390783"&gt;https://community.esri.com/message/390783#390783&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2014 05:01:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308715#M24026</guid>
      <dc:creator>ElleryChan</dc:creator>
      <dc:date>2014-08-04T05:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Hiking equation in python returns wrong results</title>
      <link>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308716#M24027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hehe, thank you&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Aleš&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Aug 2014 10:15:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/hiking-equation-in-python-returns-wrong-results/m-p/308716#M24027</guid>
      <dc:creator>GrljAles</dc:creator>
      <dc:date>2014-08-04T10:15:15Z</dc:date>
    </item>
  </channel>
</rss>

