9
votes

C # Question de classe de mathématiques

J'ai besoin de calculer Tanh-1 en C #
(et sinh-1 et cosh-1)

Je ne l'ai pas trouvé dans la bibliothèque de mathématiques .. Toute suggestion?

EDIT: Tanh pas bronzer !!


0 commentaires

4 Réponses :


8
votes

2 commentaires

Notez que le logarithme naturel n'est également aucune fonction de la classe de mathématiques standard, cependant, le logarithme général est. Vous pouvez simplement utiliser le logarithme général avec la base E (qui est une constante dans la classe de mathématiques). Ce qui est bien sûr exactement la définition du logarithme naturel. Juste une note pour des raisons de complétude @kennytm +1 pour le math-art :)


Tu as raison, j'étais trop rapide :) en effet la surcharge par défaut de math.log qui prend seulement un double est le journal naturel.



27
votes

Vous devez les dériver vous-même en utilisant les fonctions existantes par exemple. Math.sin

Vous pourriez trouver cela utile: xxx


1 commentaires

Je voulais juste ajouter: asec (x) = ACOS (1 / x), ACSC (x) = asin (1 / x), acot (x) = ATAN (1 / x)



13
votes

TO .NET-IFY David Relihan's Formulas:

public static class MathHelper
{
    // Secant 
    public static double Sec(double x)
    {
        return 1/Math.Cos(x);
    }

    // Cosecant
    public static double Cosec(double x)
    {
        return 1/Math.Sin(x);
    }

    // Cotangent 
    public static double Cotan(double x)
    {
        return 1/Math.Tan(x);
    }

    // Inverse Sine 
    public static double Arcsin(double x)
    {
        return Math.Atan(x / Math.Sqrt(-x * x + 1));
    }

    // Inverse Cosine 
    public static double Arccos(double x)
    {
        return Math.Atan(-x / Math.Sqrt(-x * x + 1)) + 2 * Math.Atan(1);
    }


    // Inverse Secant 
    public static double Arcsec(double x)
    {
        return 2 * Math.Atan(1) - Math.Atan(Math.Sign(x) / Math.Sqrt(x * x - 1));
    }

    // Inverse Cosecant 
    public static double Arccosec(double x)
    {
        return Math.Atan(Math.Sign(x) / Math.Sqrt(x * x - 1));
    }

    // Inverse Cotangent 
    public static double Arccotan(double x)
    {
        return 2 * Math.Atan(1) - Math.Atan(x);
    } 

    // Hyperbolic Sine 
    public static double HSin(double x)
    {
        return (Math.Exp(x) - Math.Exp(-x)) / 2 ;
    }

    // Hyperbolic Cosine 
    public static double HCos(double x)
    {
        return (Math.Exp(x) + Math.Exp(-x)) / 2 ;
    }

    // Hyperbolic Tangent 
    public static double HTan(double x)
    {
        return (Math.Exp(x) - Math.Exp(-x)) / (Math.Exp(x) + Math.Exp(-x));
    } 

    // Hyperbolic Secant 
    public static double HSec(double x)
    {
        return 2 / (Math.Exp(x) + Math.Exp(-x));
    } 

    // Hyperbolic Cosecant 
    public static double HCosec(double x)
    {
        return 2 / (Math.Exp(x) - Math.Exp(-x));
    } 

    // Hyperbolic Cotangent 
    public static double HCotan(double x)
    {
        return (Math.Exp(x) + Math.Exp(-x)) / (Math.Exp(x) - Math.Exp(-x));
    } 

    // Inverse Hyperbolic Sine 
    public static double HArcsin(double x)
    {
        return Math.Log(x + Math.Sqrt(x * x + 1)) ;
    }

    // Inverse Hyperbolic Cosine 
    public static double HArccos(double x)
    {
        return Math.Log(x + Math.Sqrt(x * x - 1));
    }

    // Inverse Hyperbolic Tangent 
    public static double HArctan(double x)
    {
        return Math.Log((1 + x) / (1 - x)) / 2 ;
    }

    // Inverse Hyperbolic Secant 
    public static double HArcsec(double x)
    {
        return Math.Log((Math.Sqrt(-x * x + 1) + 1) / x);
    } 

    // Inverse Hyperbolic Cosecant 
    public static double HArccosec(double x)
    {
        return Math.Log((Math.Sign(x) * Math.Sqrt(x * x + 1) + 1) / x) ;
    }

    // Inverse Hyperbolic Cotangent 
    public static double HArccotan(double x)
    {
        return Math.Log((x + 1) / (x - 1)) / 2;
    } 

    // Logarithm to base N 
    public static double LogN(double x, double n)
    {
        return Math.Log(x) / Math.Log(n);
    }
}


0 commentaires

0
votes

Il existe également une formule plus rapide pour calculer TANH, nécessitant une seule exp (), car TANH est lié à la fonction logistique:

tanh (x) = 2 / (1 + exp (-2 * x)) - 1
aussi
tanh (x) = 1 - 2 / (1 + exp (2 * x))

Voir: http://fr.wikipedia.org/wiki/logistic_function


0 commentaires