what is the syntax for TANH

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

  1. baldrick

    baldrick Guest

    Is there a syntax function to calculate tanh?

    This complains ....

    COMPUTE coeff = tanh(0.023) .
    EXECUTE .
     
    baldrick, Aug 21, 2007
    #1
    1. Advertisements

  2. 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
    #2
    1. Advertisements

  3. baldrick

    baldrick Guest

    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
    #3
  4. 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
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.