Click here to Skip to main content
Click here to Skip to main content

Special Function(s) for C#

, 15 Sep 2005
Rate this:
Please Sign up or sign in to vote.
Physical constants and special functions not found in the System.Math class

Introduction

This class contains physical constants and special functions not found in the System.Math class (C# port of the Cephes math library).

Constants

// Physical Constants in cgs Units
    
// Boltzman Constant. Units erg/deg(K) 
public const double BOLTZMAN = 1.3807e-16;
    
// Elementary Charge. Units statcoulomb 
public const double ECHARGE = 4.8032e-10;
    
// Electron Mass. Units g 
public const double EMASS = 9.1095e-28;
    
// Proton Mass. Units g 
public const double PMASS = 1.6726e-24;
    
// Gravitational Constant. Units dyne-cm^2/g^2
public const double GRAV = 6.6720e-08;
    
// Planck constant. Units erg-sec 
public const double PLANCK = 6.6262e-27;
    
// Speed of Light in a Vacuum. Units cm/sec 
public const double LIGHTSPEED = 2.9979e10;
    
// Stefan-Boltzman Constant. Units erg/cm^2-sec-deg^4 
public const double STEFANBOLTZ = 5.6703e-5;
    
// Avogadro Number. Units  1/mol 
public const double AVOGADRO = 6.0220e23;
    
// Gas Constant. Units erg/deg-mol 
public const double GASCONSTANT = 8.3144e07;
    
// Gravitational Acceleration at the Earths surface. Units cm/sec^2 
public const double GRAVACC = 980.67;
    
// Solar Mass. Units g 
public const double SOLARMASS = 1.99e33;
    
// Solar Radius. Units cm
public const double SOLARRADIUS = 6.96e10;
    
// Solar Luminosity. Units erg/sec
public const double SOLARLUM = 3.90e33;
    
// Solar Flux. Units erg/cm^2-sec
public const double SOLARFLUX = 6.41e10;
    
// Astronomical Unit (radius of the Earth's orbit). Units cm
public const double AU = 1.50e13;

Methods

/// Returns the base 10 logarithm of the specified number.
public static double log10(double x);

/// Returns the hyperbolic cosine of the specified number.
public static double cosh(double x);

/// Returns the hyperbolic sine of the specified number.
public static double sinh(double x);

/// Returns the hyperbolic tangent of the specified number.
public static double tanh(double x);

/// Returns the hyperbolic arc cosine of the specified number.
public static double acosh(double x);

/// Returns the hyperbolic arc sine of the specified number.
public static double asinh(double xx);

/// Returns the hyperbolic arc tangent of the specified number.
public static double atanh(double x);

/// Returns the Bessel function of order 0 of the specified number.
public static double j0(double x);

/// Returns the Bessel function of order 1 of the specified number.
public static double j1(double x);

/// Returns the Bessel function of order n of the specified number.
public static double jn(int n, double x);

/// Returns the Bessel function of the second kind,
/// of order 0 of the specified number.
public static double y0(double x);

/// Returns the Bessel function of the second kind,
/// of order 1 of the specified number.
public static double y1(double x);

/// Returns the Bessel function of the second kind,
/// of order n of the specified number.
public static double yn(int n, double x);

/// Returns the factorial of the specified number.
public static double fac(double x);

/// Returns the factorial of the specified number.
public static int fac(int j);

/// Returns the gamma function of the specified number.
public static double gamma(double x);

/// Return the gamma function computed by Stirling's formula.
private static double stirf(double x);

/// Returns the complemented incomplete gamma function.
public static double igamc(double a, double x);

/// Returns the incomplete gamma function.
public static double igam(double a, double x);

/// Returns the chi-square function (left hand tail).
public static double chisq(double df, double x);

/// Returns the chi-square function (right hand tail).
public static double chisqc(double df, double x);

/// Returns the sum of the first k terms of the Poisson distribution.
public static double poisson(int k, double x);

/// Returns the sum of the terms k+1 to infinity of the Poisson distribution.
public static double poissonc(int k, double x);

/// Returns the area under the Gaussian probability density function, 
///integrated from minus infinity to a.
public static double normal(double a);

/// Returns the complementary error function of the specified number.
public static double erfc(double a);

/// Returns the error function of the specified number.
public static double erf(double x);

/// Evaluates polynomial of degree N
private static double polevl(double x, double[] coef, int N);

/// Evaluates polynomial of degree N with assumption that coef[N] = 1.0
private static double p1evl(double x, double[] coef, int N);

/// Returns the natural logarithm of gamma function.
public static double lgamma(double x);

/// Returns the incomplete beta function evaluated from zero to xx.
public static double ibeta(double aa, double bb, double xx);

/// Returns the continued fraction expansion #1 for incomplete beta integral.
private static double incbcf(double a, double b, double x);

/// Returns the continued fraction expansion #2 for incomplete beta integral.
private static double incbd(double a, double b, double x);

/// Returns the power series for incomplete beta integral.
/// Use when b*x is small and x not too close to 1.
private static double pseries(double a, double b, double x);

Outroduction

I hope this will put a smile on someone's face, at least one. Smile | :)

History

  • 15th September, 2005: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Miroslav Stampar
Software Developer (Senior)
Croatia Croatia
No Biography provided
Follow on   Twitter

Comments and Discussions

 
QuestionComplementary Incomplete Gamma Functions PinmemberMember 105118748-Jan-14 10:18 
GeneralThank you. PinmemberMember 1041310819-Nov-13 18:52 
SuggestionThank you! PinmemberAhmad Davudi20-Jul-13 20:38 
GeneralThank you! PinmemberJeff Manning24-Jan-13 14:06 
QuestionThanks a lot PinmemberMember 341649812-Jan-13 3:41 
Thanks a lot for putting it together. Just one observation, it would be better to take constant arrays out of functions bodies and make them static. I am getting up to 6 times speed increase with this simple modification.
QuestionAwesome !!! ty very much! PinmemberMember 822634013-Dec-12 2:23 
QuestionCopied functions Pinmemberiliyapolak5-Apr-12 3:01 
AnswerRe: Copied functions PinmemberJay Lemmon4-Jan-14 11:26 
QuestionMACHEP Pinmemberagelospanagiotakis3-Oct-11 13:39 
QuestionLicensing PinmemberMember 10990310-Aug-09 6:02 
AnswerRe: Licensing PinmemberMember 816281415-Aug-11 11:12 
GeneralRe: Licensing PinmemberMember 816368815-Aug-11 21:12 
GeneralAh, I could kiss you!!! PinmemberMember 40338572-Apr-08 0:10 
GeneralGood work Pinmemberram kumar 20212-Sep-07 22:46 
GeneralGood work! PinmemberDesmond McCarter17-May-07 18:41 
GeneralRe: Good work! Pinmembera26gen11-Jun-07 21:54 
Generalfantastic Pinmemberrabbithacking12-Apr-07 10:40 
GeneralStrange units Pinmembermav.northwind15-Sep-05 11:40 
GeneralRe: Strange units PinmemberMiroslav Stampar15-Sep-05 22:49 
GeneralNeat, but... PinmemberKeith Farmer15-Sep-05 8:15 
GeneralRe: Neat, but... PinmemberHerbert Sauro5-Nov-05 8:59 
GeneralRe: Neat, but... PinmemberKeith Farmer5-Nov-05 10:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 15 Sep 2005
Article Copyright 2005 by Miroslav Stampar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid