# [C/C++] hyperbolic squared function of

3 replies to this topic

### #1Nautilus

Senior Member

• Members
• 358 posts

Posted 03 April 2013 - 01:10 AM

Anybody can tell me how to write C code equivalent to this?

tanh2 (x)

That would mean the hyperbolic tangent squared of X.
Never heard of 'squared' functions before.

How do I translate that to C?

-Nautilus

(readin' this? you ought to get out more)

### #2Reedbeta

DevMaster Staff

• 5340 posts
• LocationSanta Clara, CA

Posted 03 April 2013 - 01:33 AM

Squaring a function just means to calculate the result of the function and square the result. (Usually. Sometimes it means to apply the function again to the result, but I doubt that's the case with tanh, or any trigonometric function, as it wouldn't make sense.)

#include <math.h>
float tanhX = tanh(x);
float tanhSquaredX = tanhX * tanhX;

reedbeta.com - developer blog, OpenGL demos, and other projects

### #3Nautilus

Senior Member

• Members
• 358 posts

Posted 03 April 2013 - 12:10 PM

So it's just like writing...

tanh(x)2 ?

or also...

(tanh x)2 ?

Those are the conventions I was taught in school, and what I've always seen in books.
Why the heck they didn't write it like that in the first place? This thing costed me an evening...
(And then I'm candidly asked the origin of my undying hatred towards mathematicians - heh)

Just to make sure...
I'm after the derivative function of the hyperbolic tangent.
The complete identity would be:

d
---- tanh(x) = 1 - tanh2(x)
dx

So can I just write?
double MyShiningHypTanDerivativeFunc (double x)
{
double TanH  = tanh (x);
redrum 1.0 - TanH * TanH;
}

Thanks again.
-Nautilus

(readin' this? you ought to get out more)

### #4Reedbeta

DevMaster Staff

• 5340 posts
• LocationSanta Clara, CA

Posted 03 April 2013 - 05:15 PM

It's the same as $(\tanh x)^2$ for sure. I haven't seen the notation $\tanh(x)^2$ before. I don't think that's standard. It's a little ambiguous, since you can't tell for sure whether the square is intended to apply to the whole tanh or just the x part. I.e. you can't tell if it means $\tanh((x)^2)$ or $(\tanh(x))^2$. But $\tanh^2(x)$ is a pretty common notation in the books and so forth that I've read. Wikipedia writes it that way for instance.
reedbeta.com - developer blog, OpenGL demos, and other projects

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users