次の方法で共有


Math.Tanh Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Returns the hyperbolic tangent of the specified angle.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Shared Function Tanh ( _
    value As Double _
) As Double
[SecuritySafeCriticalAttribute]
public static double Tanh(
    double value
)

Parameters

Return Value

Type: System.Double
The hyperbolic tangent of value. If value is equal to NegativeInfinity, this method returns -1. If value is equal to PositiveInfinity, this method returns 1. If value is equal to NaN, this method returns NaN.

Remarks

The angle, value, must be in radians. Multiply by Math.PI/180 to convert degrees to radians.

Examples

The following example uses Tanh to evaluate certain hyperbolic tangent identities for selected values.

' Example for the hyperbolic Math.Tanh( Double ) method.

Module Example

   Public Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      outputBlock.Text &= _
          "This example of hyperbolic Math.Tanh( Double )" & _
          vbCrLf & "generates the following output." & vbCrLf
      outputBlock.Text &= _
          vbCrLf & "Evaluate these hyperbolic " & _
          "identities with selected values for X:" & vbCrLf
      outputBlock.Text &= "   tanh(X) = sinh(X) / cosh(X)" & vbCrLf
      outputBlock.Text &= "   tanh(2 * X) = 2 * tanh(X) / (1 + tanh^2(X))" & vbCrLf

      UseTanh(outputBlock, 0.1)
      UseTanh(outputBlock, 1.2)
      UseTanh(outputBlock, 4.9)

      outputBlock.Text &= _
          vbCrLf & "Evaluate [tanh(X + Y) == (tanh(X) + " & _
          "tanh(Y)) / (1 + tanh(X) * tanh(Y))]" & _
          vbCrLf & "with selected values for X and Y:" & vbCrLf

      UseTwoArgs(outputBlock, 0.1, 1.2)
      UseTwoArgs(outputBlock, 1.2, 4.9)
   End Sub 'Main

   ' Evaluate hyperbolic identities with a given argument.
   Sub UseTanh(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal arg As Double)
      Dim tanhArg As Double = Math.Tanh(arg)

      ' Evaluate tanh(X) = sinh(X) / cosh(X).
      outputBlock.Text &= String.Format( _
          vbCrLf & "                       Math.Tanh({0}) = {1:E16}" & _
          vbCrLf & "      Math.Sinh({0}) / Math.Cosh({0}) = {2:E16}", _
          arg, tanhArg, Math.Sinh(arg) / Math.Cosh(arg)) & vbCrLf

      ' Evaluate tanh(2 * X) = 2 * tanh(X) / (1 + tanh^2(X)).
      outputBlock.Text &= String.Format( _
          "                   2 * Math.Tanh({0}) /", _
          arg, 2.0 * tanhArg) & vbCrLf
      outputBlock.Text &= String.Format( _
          "             (1 + (Math.Tanh({0}))^2) = {1:E16}", _
          arg, 2.0 * tanhArg / (1.0 + tanhArg * tanhArg)) & vbCrLf
      outputBlock.Text &= String.Format( _
          "                       Math.Tanh({0}) = {1:E16}", _
          2.0 * arg, Math.Tanh((2.0 * arg))) & vbCrLf
   End Sub 'UseTanh

   ' Evaluate a hyperbolic identity that is a function of two arguments.
   Sub UseTwoArgs(ByVal outputBlock As System.Windows.Controls.TextBlock, ByVal argX As Double, ByVal argY As Double)

      ' Evaluate tanh(X + Y) = (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y)).
      outputBlock.Text &= String.Format( _
          vbCrLf & "    (Math.Tanh({0}) + Math.Tanh({1})) /" & _
          vbCrLf & "(1 + Math.Tanh({0}) * Math.Tanh({1})) = {2:E16}", _
          argX, argY, (Math.Tanh(argX) + Math.Tanh(argY)) / _
          (1.0 + Math.Tanh(argX) * Math.Tanh(argY))) & vbCrLf
      outputBlock.Text &= String.Format( _
          "                       Math.Tanh({0}) = {1:E16}", _
          argX + argY, Math.Tanh(argX + argY)) & vbCrLf

   End Sub 'UseTwoArgs
End Module 'DemoTanh

' This example of hyperbolic Math.Tanh( Double )
' generates the following output.
' 
' Evaluate these hyperbolic identities with selected values for X:
'    tanh(X) = sinh(X) / cosh(X)
'    tanh(2 * X) = 2 * tanh(X) / (1 + tanh^2(X))
' 
'                        Math.Tanh(0.1) = 9.9667994624955819E-002
'       Math.Sinh(0.1) / Math.Cosh(0.1) = 9.9667994624955819E-002
'                    2 * Math.Tanh(0.1) /
'              (1 + (Math.Tanh(0.1))^2) = 1.9737532022490401E-001
'                        Math.Tanh(0.2) = 1.9737532022490401E-001
' 
'                        Math.Tanh(1.2) = 8.3365460701215521E-001
'       Math.Sinh(1.2) / Math.Cosh(1.2) = 8.3365460701215521E-001
'                    2 * Math.Tanh(1.2) /
'              (1 + (Math.Tanh(1.2))^2) = 9.8367485769368024E-001
'                        Math.Tanh(2.4) = 9.8367485769368024E-001
' 
'                        Math.Tanh(4.9) = 9.9988910295055444E-001
'       Math.Sinh(4.9) / Math.Cosh(4.9) = 9.9988910295055433E-001
'                    2 * Math.Tanh(4.9) /
'              (1 + (Math.Tanh(4.9))^2) = 9.9999999385024030E-001
'                        Math.Tanh(9.8) = 9.9999999385024030E-001
' 
' Evaluate [tanh(X + Y) == (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y))]
' with selected values for X and Y:
' 
'     (Math.Tanh(0.1) + Math.Tanh(1.2)) /
' (1 + Math.Tanh(0.1) * Math.Tanh(1.2)) = 8.6172315931330645E-001
'                        Math.Tanh(1.3) = 8.6172315931330634E-001
' 
'     (Math.Tanh(1.2) + Math.Tanh(4.9)) /
' (1 + Math.Tanh(1.2) * Math.Tanh(4.9)) = 9.9998993913939649E-001
'                        Math.Tanh(6.1) = 9.9998993913939649E-001
// Example for the hyperbolic Math.Tanh( double ) method.
using System;

class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text +=
          "This example of hyperbolic Math.Tanh( double )\n" +
          "generates the following output." + "\n";
      outputBlock.Text +=
          "\nEvaluate these hyperbolic identities " +
          "with selected values for X:" + "\n";
      outputBlock.Text += "   tanh(X) == sinh(X) / cosh(X)" + "\n";
      outputBlock.Text +=
          "   tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X))" + "\n";

      UseTanh(outputBlock, 0.1);
      UseTanh(outputBlock, 1.2);
      UseTanh(outputBlock, 4.9);

      outputBlock.Text +=
          "\nEvaluate [tanh(X + Y) == (tanh(X) + tanh(Y)) " +
          "/ (1 + tanh(X) * tanh(Y))]" +
          "\nwith selected values for X and Y:" + "\n";

      UseTwoArgs(outputBlock, 0.1, 1.2);
      UseTwoArgs(outputBlock, 1.2, 4.9);
   }

   // Evaluate hyperbolic identities with a given argument.
   static void UseTanh(System.Windows.Controls.TextBlock outputBlock, double arg)
   {
      double tanhArg = Math.Tanh(arg);

      // Evaluate tanh(X) == sinh(X) / cosh(X).
      outputBlock.Text += String.Format(
          "\n                       Math.Tanh({0}) == {1:E16}\n" +
          "      Math.Sinh({0}) / Math.Cosh({0}) == {2:E16}",
          arg, tanhArg, (Math.Sinh(arg) / Math.Cosh(arg))) + "\n";

      // Evaluate tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X)).
      outputBlock.Text += String.Format(
          "                   2 * Math.Tanh({0}) /",
          arg, 2.0 * tanhArg) + "\n";
      outputBlock.Text += String.Format(
          "             (1 + (Math.Tanh({0}))^2) == {1:E16}",
          arg, 2.0 * tanhArg / (1.0 + tanhArg * tanhArg)) + "\n";
      outputBlock.Text += String.Format(
          "                       Math.Tanh({0}) == {1:E16}",
          2.0 * arg, Math.Tanh(2.0 * arg)) + "\n";
   }

   // Evaluate a hyperbolic identity that is a function of two arguments.
   static void UseTwoArgs(System.Windows.Controls.TextBlock outputBlock, double argX, double argY)
   {
      // Evaluate tanh(X + Y) == (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y)).
      outputBlock.Text += String.Format(
          "\n    (Math.Tanh({0}) + Math.Tanh({1})) /\n" +
          "(1 + Math.Tanh({0}) * Math.Tanh({1})) == {2:E16}",
          argX, argY, (Math.Tanh(argX) + Math.Tanh(argY)) /
          (1.0 + Math.Tanh(argX) * Math.Tanh(argY))) + "\n";
      outputBlock.Text += String.Format(
          "                       Math.Tanh({0}) == {1:E16}",
          argX + argY, Math.Tanh(argX + argY)) + "\n";
   }
}

/*
This example of hyperbolic Math.Tanh( double )
generates the following output.

Evaluate these hyperbolic identities with selected values for X:
   tanh(X) == sinh(X) / cosh(X)
   tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X))

                       Math.Tanh(0.1) == 9.9667994624955819E-002
      Math.Sinh(0.1) / Math.Cosh(0.1) == 9.9667994624955819E-002
                   2 * Math.Tanh(0.1) /
             (1 + (Math.Tanh(0.1))^2) == 1.9737532022490401E-001
                       Math.Tanh(0.2) == 1.9737532022490401E-001

                       Math.Tanh(1.2) == 8.3365460701215521E-001
      Math.Sinh(1.2) / Math.Cosh(1.2) == 8.3365460701215521E-001
                   2 * Math.Tanh(1.2) /
             (1 + (Math.Tanh(1.2))^2) == 9.8367485769368024E-001
                       Math.Tanh(2.4) == 9.8367485769368024E-001

                       Math.Tanh(4.9) == 9.9988910295055444E-001
      Math.Sinh(4.9) / Math.Cosh(4.9) == 9.9988910295055433E-001
                   2 * Math.Tanh(4.9) /
             (1 + (Math.Tanh(4.9))^2) == 9.9999999385024030E-001
                       Math.Tanh(9.8) == 9.9999999385024030E-001

Evaluate [tanh(X + Y) == (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y))]
with selected values for X and Y:

    (Math.Tanh(0.1) + Math.Tanh(1.2)) /
(1 + Math.Tanh(0.1) * Math.Tanh(1.2)) == 8.6172315931330645E-001
                       Math.Tanh(1.3) == 8.6172315931330634E-001

    (Math.Tanh(1.2) + Math.Tanh(4.9)) /
(1 + Math.Tanh(1.2) * Math.Tanh(4.9)) == 9.9998993913939649E-001
                       Math.Tanh(6.1) == 9.9998993913939649E-001
*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

See Also

Reference