2017-07-31 15 views

回答

0

這是一個快速的解決方案,我沒有試過,以獲得最大的精確度和性能。根據您的REQ,你可能需要調整的數字格式,精度,計算邏輯等

create or replace function calc_sn_pdf(x in number) return number 
is 
pi  CONSTANT NUMBER := 3.14159265358979; 
begin 
    return 1/sqrt(2*pi) * exp(-x*x/2); 
end; 
/

民防部隊必須近似(因爲它是沒有簡單的數學公式AZ積分功能),一個可能的近似實施如下。維基百科上可以找到許多其他近似值。

create or replace function calc_sn_cdf(x in number) return number 
is 
b0 CONSTANT NUMBER := 0.2316419; 
b1 CONSTANT NUMBER := 0.319381530; 
b2 CONSTANT NUMBER := -0.356563782; 
b3 CONSTANT NUMBER := 1.781477937; 
b4 CONSTANT NUMBER := -1.821255978; 
b5 CONSTANT number := 1.330274429; 
v_t number; 
begin 
    --see 26.2.17 at http://people.math.sfu.ca/~cbm/aands/page_932.htm 
    --see https://en.wikipedia.org/wiki/Normal_distribution#Numerical_approximations_for_the_normal_CDF 
    --Zelen & Severo (1964) approximation 
    if x < 0 then 
    --this approximation works for x>0, but cdf is symmetric for x=0: 
    return 1 - calc_sn_cdf(-x); 
    else 
    v_t := 1/(1 + b0*x); 
    return 1 - calc_sn_pdf(x)*(b1*v_t + b2*v_t*v_t + b3*v_t*v_t*v_t + b4*v_t*v_t*v_t*v_t + b5*v_t*v_t*v_t*v_t*v_t); 
    end if;  
end; 
/

順便說一句,如果你需要運行這些功能很多的時間,這將是打開本地PL/SQL編譯有用。