当前位置: 首页>>代码示例>>C#>>正文


C# Math.Tanh方法代码示例

本文整理汇总了C#中System.Math.Tanh方法的典型用法代码示例。如果您正苦于以下问题:C# Math.Tanh方法的具体用法?C# Math.Tanh怎么用?C# Math.Tanh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Math的用法示例。


在下文中一共展示了Math.Tanh方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

// Example for the hyperbolic Math.Tanh( double ) method.
using System;

class DemoTanh 
{
    public static void Main() 
    {
        Console.WriteLine( 
            "This example of hyperbolic Math.Tanh( double )\n" +
            "generates the following output." );
        Console.WriteLine( 
            "\nEvaluate these hyperbolic identities " +
            "with selected values for X:" );
        Console.WriteLine( "   tanh(X) == sinh(X) / cosh(X)" );
        Console.WriteLine( 
            "   tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X))" );

        UseTanh(0.1);
        UseTanh(1.2);
        UseTanh(4.9);

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

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

    // Evaluate hyperbolic identities with a given argument.
    static void UseTanh(double arg)
    {
        double tanhArg = Math.Tanh(arg);

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

        // Evaluate tanh(2 * X) == 2 * tanh(X) / (1 + tanh^2(X)).
        Console.WriteLine( 
            "                   2 * Math.Tanh({0}) /", 
            arg, 2.0 * tanhArg );
        Console.WriteLine( 
            "             (1 + (Math.Tanh({0}))^2) == {1:E16}", 
            arg, 2.0 * tanhArg / (1.0 + tanhArg * tanhArg ) );
        Console.WriteLine( 
            "                       Math.Tanh({0}) == {1:E16}", 
            2.0 * arg, Math.Tanh(2.0 * arg) );
    }

    // Evaluate a hyperbolic identity that is a function of two arguments.
    static void UseTwoArgs(double argX, double argY)
    {
        // Evaluate tanh(X + Y) == (tanh(X) + tanh(Y)) / (1 + tanh(X) * tanh(Y)).
        Console.WriteLine( 
            "\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)) );
        Console.WriteLine( 
            "                       Math.Tanh({0}) == {1:E16}",
            argX + argY, Math.Tanh(argX + argY));
    }
}
开发者ID:.NET开发者,项目名称:System,代码行数:67,代码来源:Math.Tanh

输出:

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


注:本文中的System.Math.Tanh方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。