# what is the syntax for TANH

Discussion in 'SPSS' started by baldrick, Aug 21, 2007.

1. ### baldrickGuest

Is there a syntax function to calculate tanh?

This complains ....

COMPUTE coeff = tanh(0.023) .
EXECUTE .

baldrick, Aug 21, 2007

2. ### Marius de PijperGuest

Hi Baldrick,

SPSS does not know tanh.
You have to use the definition of tanh:

compute coeff = (exp(0.023) - exp(-0.023)) / (exp(0.023) + exp(-0.023)).

or you can use this in a macro:

DEFINE tanh(!POSITIONAL !TOKENS(1) / !POSITIONAL !TOKENS(1)) .
compute !1 = (exp(!2) - exp(-!2)) / (exp(!2) + exp(-!2)) .
!ENDDEFINE .

tanh coeff 0.023 .
execute .

Marius

Marius de Pijper, Aug 21, 2007

3. ### baldrickGuest

Thanks Marius, you just confirmed what I thought.

If I use the macro definition for tanh and want to calculate the
following, what does the syntax then become? Much appreciate your
help.

COMPUTE coeff =
5.85510513443911
+
(tanh(-8.61973985417518E-02 +
(var_1 * 3.04406148309044E-02) +
(var_2 * 0.911605547009379)
) * -0.182641407179637)

baldrick, Aug 21, 2007
4. ### Marius de PijperGuest

I'm afraid you will have to split up this statement into three statements:

compute #t1 = -8.61973985417518E-02 +
(var_1 * 3.04406148309044E-02) +
(var_2 * 0.911605547009379) .
tanh #t2 #t1 .
compute coeff = 5.85510513443911 + #t2 * -0.182641407179637 .

Marius

Marius de Pijper, Aug 21, 2007