<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Looking at the heading "tan" on<br>
    &nbsp;&nbsp;&nbsp;
    <a class="moz-txt-link-freetext" href="http://www.coin-or.org/CppAD/Doc/std_math_ad.xml#Derivatives.tanh">http://www.coin-or.org/CppAD/Doc/std_math_ad.xml#Derivatives.tanh</a><br>
    you will see that tanh is currently implemented as<br>
    &nbsp;&nbsp;&nbsp; sinh(x) / cosh(x)<br>
    which yields inf / inf&nbsp; for large values of x.<br>
    <br>
    Looking at the heading "Tan and Tanh" in the CppAD wish list<br>
    &nbsp;&nbsp;&nbsp; <a class="moz-txt-link-freetext" href="http://www.coin-or.org/CppAD/Doc/wishlist.xml#Tan%20and%20Tanh">http://www.coin-or.org/CppAD/Doc/wishlist.xml#Tan%20and%20Tanh</a><br>
    you will see an item that would fix this problem.<br>
    <br>
    I have added a user atomic example that tests this solution; see<br>
    &nbsp;&nbsp;&nbsp; <a class="moz-txt-link-freetext" href="http://www.coin-or.org/CppAD/Doc/user_tan.cpp.xml">http://www.coin-or.org/CppAD/Doc/user_tan.cpp.xml</a><br>
    In particular, see the following section of its correctness test:&nbsp; <br>
    &nbsp;&nbsp;&nbsp; // check tanh results for a large value of x<br>
    &nbsp;&nbsp;&nbsp; CPPAD_TEST_VECTOR&lt;float&gt; x(n), f(m);<br>
    &nbsp;&nbsp;&nbsp; x[0]&nbsp; = std::numeric_limits&lt;float&gt;::max() / two;<br>
    &nbsp;&nbsp;&nbsp; f&nbsp;&nbsp;&nbsp;&nbsp; = F.Forward(0, x);<br>
    &nbsp;&nbsp;&nbsp; tanh&nbsp; = 1.;<br>
    &nbsp;&nbsp;&nbsp; ok&nbsp;&nbsp; &amp;= NearEqual(f[1], tanh, eps, eps);<br>
    &nbsp;&nbsp;&nbsp; df&nbsp;&nbsp;&nbsp; = F.Forward(1, dx);<br>
    &nbsp;&nbsp;&nbsp; tanhp = 0.;<br>
    &nbsp;&nbsp;&nbsp; ok&nbsp;&nbsp; &amp;= NearEqual(df[1], tanhp, eps, eps);<br>
    &nbsp;<br>
    The next and final step in this effort will be to complete the wish
    list item using the algorithms in user_tan.cpp.<br>
    <br>
    P.S.<br>
    I tried the solution<br>
    &nbsp;&nbsp;&nbsp; tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
    = 1 - 2 / (1 + exp(2x))
    <br>
    which works for function values, but when evaluating derivatives one
    gets<br>
    &nbsp;&nbsp;&nbsp; 4 * exp(2x) / ( 1 + exp(2x) )^2<br>
    which yields inf / inf = nan for large values of x.<br>
    <br>
    <br>
    On 7/12/2011 10:37 AM, Srikrishnan Ramadurai wrote:<br>
    <blockquote
cite="mid:CALEDsf-0m3MjZFJv5UDXCT48f2TWOUhzg-j4pwaptH+U7ykA-w@mail.gmail.com"
      type="cite">
      <pre wrap="">Hi,

I am trying to find the jacobian for a function that has a few tanh
functions in it . I've noticed that the differentiation of tanh function
fails for some arguments.

A test example  is y=tanh(c*x1)+x2

The Jacobian of y is obtained when c is small say 20, but fails with an
error when c is something like 100. This is using the driver function
Jacobian.

This is the error that I receive.

cppad-20110711 error from a known source:
y_p = f.Forward(p, x_p): has a nan in y_p for p = 0.
Error detected by false result for
    false

Is there something that I need to do to make the differentiation work? Any
help is appreciated.

The sample code in c++ is attached. The system is a intel core 2 quad
machine running on 64 bit ubuntu 10.04.

Thanks.

Regards
Srikrishnan

</pre>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
CppAD mailing list
<a class="moz-txt-link-abbreviated" href="mailto:CppAD@list.coin-or.org">CppAD@list.coin-or.org</a>
<a class="moz-txt-link-freetext" href="http://list.coin-or.org/mailman/listinfo/cppad">http://list.coin-or.org/mailman/listinfo/cppad</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>