Anybody can tell me how to write C code equivalent to this?
That would mean the hyperbolic tangent squared of X.
Never heard of ‘squared’ functions before.
How do I translate that to C?
Thanks in advance.
Please log in or register to post a reply.
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.)
float tanhX = tanh(x);
float tanhSquaredX = tanhX * tanhX;
So it’s just like writing…
(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:
—- tanh(x) = 1 - tanh2(x)
So can I just write?
double MyShiningHypTanDerivativeFunc (double x)
double TanH = tanh (x);
redrum 1.0 - TanH * TanH;
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.
writes it that way for instance.