C#,数值计算——柯西分布(Cauchy distribution)的计算方法与源程序

柯西分布(Cauchy distribution)简介

The Cauchy distribution, also called the Lorentzian distribution or Lorentz distribution, is a continuous distribution describing resonance behavior. It also describes the distribution of horizontal distances at which a line segment tilted at a random angle cuts the x-axis.

Let theta represent the angle that a line, with fixed point of rotation, makes with the vertical axis, as shown above. Then:

C#,数值计算——柯西分布(Cauchy distribution)的计算方法与源程序_第1张图片

The general Cauchy distribution and its cumulative distribution can be written as

 

where b is the half width at half maximum and m is the statistical median. In the illustration about, m=0.

The Cauchy distribution is implemented in the Wolfram Language as CauchyDistribution[m, Gamma/2].

The characteristic function is

C#,数值计算——柯西分布(Cauchy distribution)的计算方法与源程序_第2张图片

柯西分布(Cauchy distribution)计算的源程序

using System;

namespace Legalsoft.Truffer
{
    ///


    /// Cauchy distribution.
    ///

    public class Cauchydist
    {
        private double mu { get; set; }
        private double sig { get; set; }

        public Cauchydist(double mmu = 0.0, double ssig = 1.0)
        {
            this.mu = mmu;
            this.sig = ssig;
            if (sig <= 0.0)
            {
                throw new Exception("bad sig in Cauchydist");
            }
        }

        public double p(double x)
        {
            return 0.318309886183790671 / (sig * (1.0 + Globals.SQR((x - mu) / sig)));
        }

        public double cdf(double x)
        {
            return 0.5 + 0.318309886183790671 * Math.Atan2(x - mu, sig);
        }

        public double invcdf(double p)
        {
            if (p <= 0.0 || p >= 1.0)
            {
                throw new Exception("bad p in Cauchydist");
            }
            return mu + sig * Math.Tan(3.14159265358979324 * (p - 0.5));
        }
    }
}
 

你可能感兴趣的:(C#数值计算,Numerical,Recipes,c#,开发语言,数值计算)