Click here to Skip to main content
15,881,559 members
Articles / Programming Languages / C#
Article

Special Function(s) for C#

Rate me:
Please Sign up or sign in to vote.
3.60/5 (33 votes)
15 Sep 2005CPOL 97.1K   3.4K   27   25
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

C#
// 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

C#
/// 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. :)

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)


Written By
Software Developer (Senior)
Croatia Croatia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionnon-integer orders for Bessel functions Pin
MDThommo8131-Dec-19 17:34
MDThommo8131-Dec-19 17:34 
QuestionI think I love you Pin
Member 1091072416-Sep-15 7:41
Member 1091072416-Sep-15 7:41 
GeneralGreat job Pin
joni50para21-Nov-14 2:48
joni50para21-Nov-14 2:48 
QuestionComplementary Incomplete Gamma Functions Pin
Member 105118748-Jan-14 10:18
Member 105118748-Jan-14 10:18 
GeneralThank you. Pin
ShawnZhang198319-Nov-13 18:52
professionalShawnZhang198319-Nov-13 18:52 
SuggestionThank you! Pin
Ahmad Davudi20-Jul-13 20:38
Ahmad Davudi20-Jul-13 20:38 
GeneralThank you! Pin
Jeff Manning24-Jan-13 14:06
Jeff Manning24-Jan-13 14:06 
QuestionThanks a lot Pin
Member 341649812-Jan-13 3:41
Member 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! Pin
Member 822634013-Dec-12 2:23
Member 822634013-Dec-12 2:23 
QuestionCopied functions Pin
iliyapolak5-Apr-12 3:01
iliyapolak5-Apr-12 3:01 
AnswerRe: Copied functions Pin
Jay Lemmon4-Jan-14 11:26
Jay Lemmon4-Jan-14 11:26 
QuestionMACHEP Pin
agelospanagiotakis3-Oct-11 13:39
agelospanagiotakis3-Oct-11 13:39 
QuestionLicensing Pin
Member 10990310-Aug-09 6:02
Member 10990310-Aug-09 6:02 
AnswerRe: Licensing Pin
Member 816281415-Aug-11 11:12
Member 816281415-Aug-11 11:12 
GeneralRe: Licensing Pin
Member 816368815-Aug-11 21:12
Member 816368815-Aug-11 21:12 
GeneralAh, I could kiss you!!! Pin
Member 40338572-Apr-08 0:10
Member 40338572-Apr-08 0:10 
GeneralGood work Pin
ram kumar 20212-Sep-07 22:46
ram kumar 20212-Sep-07 22:46 
GeneralGood work! Pin
Desmond McCarter17-May-07 18:41
Desmond McCarter17-May-07 18:41 
GeneralRe: Good work! Pin
a26gen11-Jun-07 21:54
a26gen11-Jun-07 21:54 
Generalfantastic Pin
rabbithacking12-Apr-07 10:40
rabbithacking12-Apr-07 10:40 
GeneralStrange units Pin
mav.northwind15-Sep-05 11:40
mav.northwind15-Sep-05 11:40 
GeneralRe: Strange units Pin
Miroslav Stampar15-Sep-05 22:49
Miroslav Stampar15-Sep-05 22:49 
GeneralNeat, but... Pin
Keith Farmer15-Sep-05 8:15
Keith Farmer15-Sep-05 8:15 
GeneralRe: Neat, but... Pin
Herbert Sauro5-Nov-05 8:59
Herbert Sauro5-Nov-05 8:59 
GeneralRe: Neat, but... Pin
Keith Farmer5-Nov-05 10:28
Keith Farmer5-Nov-05 10:28 

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

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