全部 论坛 文章 培训 人才 圈子 签到 VIP 话题 收藏 7Tool SQE 体系 管理 5手册 Rohs 认证 六西格玛 精益 精华 ai问答 评估我
资料库上万份资料 AIAI问答智能答疑 评估我能力评估
纯干货!SPC分析中用到的伽玛函数(Gamma)并奉上代码
头像
伽玛函数(Gamma),也叫欧拉第二积分,是阶乘函数在实数与复数上扩展的一类函数。该函数在分析学、概率论、偏微分方程和组合数学中有重要的应用。与之有密切联系的函数是贝塔函数,也叫第一类欧拉积分,可以用来快速计算同伽马函数形式相类似的积分。


function [Fun_SPC_Gamma](@x float)
returns float
begin
 
    if @x <= 0
        return 1
    declare @gamma float 
    set @gamma = 0.577215664901532860606512090
 
    if @x <0.001
        return 1.0 / (@x * (1.0 + @gamma * @x));
 
    if @x < 12
    begin
 
        declare @y float
        set @y =@x
 
        declare @n int 
        set @n = 0
 
        declare @arg_was_less_than_one bit
        if @y < 1.0
            set @arg_was_less_than_one = 1
        else
            set @arg_was_less_than_one = 0
 
        if @arg_was_less_than_one = 1
            set @y = @y + 1
        else
        begin
             
            set @n= cast(Floor(@y) as int) - 1
            set @y =@y - @n
        end
 
        declare @tbP table
        (
            id int,
            const float
        )     
        insert into @tbP values(1,-1.71618513886549492533811E+0)
        insert into @tbP values(2,2.47656508055759199108314E+1)
        insert into @tbP values(3,-3.79804256470945635097577E+2)
        insert into @tbP values(4,6.29331155312818442661052E+2)
        insert into @tbP values(5,8.66966202790413211295064E+2)
        insert into @tbP values(6,-3.14512729688483675254357E+4)
        insert into @tbP values(7,-3.61444134186911729807069E+4)
        insert into @tbP values(8,6.64561438202405440627855E+4)
 
        declare @tbQ table
        (
            id int,
            const float
        )     
        insert into @tbQ values(1,-3.08402300119738975254353E+1)
        insert into @tbQ values(2,3.15350626979604161529144E+2)
        insert into @tbQ values(3,-1.01515636749021914166146E+3)
        insert into @tbQ values(4,-3.10777167157231109440444E+3)
        insert into @tbQ values(5,2.25381184209801510330112E+4)
        insert into @tbQ values(6,4.75584627752788110767815E+3)
        insert into @tbQ values(7,-1.34659959864969306392456E+5)
        insert into @tbQ values(8,-1.15132259675553483497211E+5)
 
        declare @num float
        declare @den float
        set @num = 0
        set @den = 1
 
        declare @i int 
        declare @z float
        set @z = @y - 1
 
        set @i = 1
 
        while @i <=8
        begin
 
            declare @p float
            declare @q float
 
            select
                @p = const
            from @tbP t 
            where id = @i
 
            select 
                @q = const
            from @tbQ t
            where id = @i
 
            set @num = (@num + @p) * @z
            set @den = @den * @z + @q
 
            set @i = @i + 1
        end
 
        declare @result float
        set @result = @num/@den + 1.0
 
        if @arg_was_less_than_one = 1
        begin
            set @result = @result/(@y - 1)
        end
        else
        begin
             
            declare @j int
            set @j = 0
            while @j< @n 
            begin
                set @result  = @result * @y
                set @y =@y + 1
                set @j = @j + 1
            end
 
        end
 
        return @result
    end
 
    if @x > 171.624
        return 1
 
    return Exp(dbo.Fun_SPC_LogGamma(@x))
 
end

凯特勒科技
2 回答 2022 浏览 2023-09-06
(ISO 9001/ISO 14001/ISO 45001)内审员4天 5000元查看 ›
共 2 个回答 按票数 最新
头像
对“干货”的概念一定是存在了“误解”~哦哈哈哈
对应用人员来说,毫无价值
2023-12-18 14:32
本问题共 2 个回答,登录后查看全部
登录查看
IMS (ISO 9001/ISO 14001/ISO 45001)内审员4天 5000元查看 › IATF16969内审员4天 5000元查看 ›
相关问题
FMEA的实际应用节选~FMEA的作用(查不到的干货)
3 回答 · 5907 浏览
不拿出点自己的“干货”一个月就会被踢出这个圈子
7 回答 · 2269 浏览
gamma 函数
17 回答 · 7325 浏览
谁知道gamma 函数?
6 回答 · 3084 浏览
伽玛分布
0 回答 · 2570 浏览
如何计算gamma
1 回答 · 3424 浏览
关于计算GRR时用到的函数
7 回答 · 3564 浏览
在品质管理统计数据上,需要运用到EXCEL其中哪些函数啊?
1 回答 · 1464 浏览
关于什么是“干货”
1 回答 · 2309 浏览
测量系统分析-MSA(定量型数据),干货,很实用
58 回答 · 3425 浏览
首页 发现 +发布 消息 我的
6S
把 6SQ 添加到桌面
像 App 一样快速访问,体验更流畅