前言:
最近帮别人搞了jionPoint统计癌症趋势。朋友问了,标准正态分布表到底是怎么算出来的?
研究了一下,主要还是通过泰勒公式迭代法求出来的。
目录
1: 计算原理
2: 代码实现
一 计算原理
从图上很明显可以看到
书上的计算过程通过:
这里
为上一点
为下一个点
,
算法流程:
初始条件:
迭代
二 代码实现
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 24 17:50:21 2020
@author: chengxf2
"""
import numpy as np
import matplotlib.pyplot as plt
"""
一阶级导数,二阶导数乘以-u就行了
"""
def derivative(u):
a = 1.0/np.sqrt(2.0*np.math.pi)
b = -np.power(u,2)/2.0
c = np.exp(b)*a
return c
def Calc():
a = 0.5 #相当于余F(x0)
b = np.power(0.01,2)
for iter in range(300):
u1 = iter*0.01
u2 = (iter+1)*0.01
a1 = derivative(u1) #一阶导数
a2 = -a1*(u1/2.0)*b #二阶导数
f2 = a+a1*0.01+a2
#print("\n iter ",f2)
print("\t u:",u2,"\t d: %.4f"%f2)
a = f2
Calc()
u: 0.01 d: 0.5040
u: 0.02 d: 0.5080
u: 0.03 d: 0.5120
u: 0.04 d: 0.5160
u: 0.05 d: 0.5199
u: 0.06 d: 0.5239
u: 0.07 d: 0.5279
u: 0.08 d: 0.5319
u: 0.09 d: 0.5359
u: 0.1 d: 0.5398
u: 0.11 d: 0.5438
u: 0.12 d: 0.5478
u: 0.13 d: 0.5517
u: 0.14 d: 0.5557
u: 0.15 d: 0.5596
u: 0.16 d: 0.5636
u: 0.17 d: 0.5675
u: 0.18 d: 0.5714
u: 0.19 d: 0.5753
u: 0.2 d: 0.5793
u: 0.21 d: 0.5832
u: 0.22 d: 0.5871
u: 0.23 d: 0.5910
u: 0.24 d: 0.5948
u: 0.25 d: 0.5987
u: 0.26 d: 0.6026
u: 0.27 d: 0.6064
u: 0.28 d: 0.6103
u: 0.29 d: 0.6141
u: 0.3 d: 0.6179
u: 0.31 d: 0.6217
u: 0.32 d: 0.6255
u: 0.33 d: 0.6293
u: 0.34 d: 0.6331
u: 0.35000000000000003 d: 0.6368
u: 0.36 d: 0.6406
u: 0.37 d: 0.6443
u: 0.38 d: 0.6480
u: 0.39 d: 0.6517
u: 0.4 d: 0.6554
u: 0.41000000000000003 d: 0.6591
u: 0.42 d: 0.6628
u: 0.43 d: 0.6664
u: 0.44 d: 0.6700
u: 0.45 d: 0.6736
u: 0.46 d: 0.6772
u: 0.47000000000000003 d: 0.6808
u: 0.48 d: 0.6844
u: 0.49 d: 0.6879
u: 0.5 d: 0.6915
u: 0.51 d: 0.6950
u: 0.52 d: 0.6985
u: 0.53 d: 0.7019
u: 0.54 d: 0.7054
u: 0.55 d: 0.7088
u: 0.56 d: 0.7123
u: 0.5700000000000001 d: 0.7157
u: 0.58 d: 0.7190
u: 0.59 d: 0.7224
u: 0.6 d: 0.7258
u: 0.61 d: 0.7291
u: 0.62 d: 0.7324
u: 0.63 d: 0.7357
u: 0.64 d: 0.7389
u: 0.65 d: 0.7422
u: 0.66 d: 0.7454
u: 0.67 d: 0.7486
u: 0.68 d: 0.7518
u: 0.6900000000000001 d: 0.7549
u: 0.7000000000000001 d: 0.7580
u: 0.71 d: 0.7612
u: 0.72 d: 0.7642
u: 0.73 d: 0.7673
u: 0.74 d: 0.7704
u: 0.75 d: 0.7734
u: 0.76 d: 0.7764
u: 0.77 d: 0.7794
u: 0.78 d: 0.7823
u: 0.79 d: 0.7852
u: 0.8 d: 0.7881
u: 0.81 d: 0.7910
u: 0.8200000000000001 d: 0.7939
u: 0.8300000000000001 d: 0.7967
u: 0.84 d: 0.7995
u: 0.85 d: 0.8023
u: 0.86 d: 0.8051
u: 0.87 d: 0.8079
u: 0.88 d: 0.8106
u: 0.89 d: 0.8133
u: 0.9 d: 0.8159
u: 0.91 d: 0.8186
u: 0.92 d: 0.8212
u: 0.93 d: 0.8238
u: 0.9400000000000001 d: 0.8264
u: 0.9500000000000001 d: 0.8289
u: 0.96 d: 0.8315
u: 0.97 d: 0.8340
u: 0.98 d: 0.8365
u: 0.99 d: 0.8389
u: 1.0 d: 0.8413
u: 1.01 d: 0.8438
u: 1.02 d: 0.8461
u: 1.03 d: 0.8485
u: 1.04 d: 0.8508
u: 1.05 d: 0.8531
u: 1.06 d: 0.8554
u: 1.07 d: 0.8577
u: 1.08 d: 0.8599
u: 1.09 d: 0.8621
u: 1.1 d: 0.8643
u: 1.11 d: 0.8665
u: 1.12 d: 0.8686
u: 1.1300000000000001 d: 0.8708
u: 1.1400000000000001 d: 0.8729
u: 1.1500000000000001 d: 0.8749
u: 1.16 d: 0.8770
u: 1.17 d: 0.8790
u: 1.18 d: 0.8810
u: 1.19 d: 0.8830
u: 1.2 d: 0.8849
u: 1.21 d: 0.8869
u: 1.22 d: 0.8888
u: 1.23 d: 0.8907
u: 1.24 d: 0.8925
u: 1.25 d: 0.8944
u: 1.26 d: 0.8962
u: 1.27 d: 0.8980
u: 1.28 d: 0.8997
u: 1.29 d: 0.9015
u: 1.3 d: 0.9032
u: 1.31 d: 0.9049
u: 1.32 d: 0.9066
u: 1.33 d: 0.9082
u: 1.34 d: 0.9099
u: 1.35 d: 0.9115
u: 1.36 d: 0.9131
u: 1.37 d: 0.9147
u: 1.3800000000000001 d: 0.9162
u: 1.3900000000000001 d: 0.9177
u: 1.4000000000000001 d: 0.9192
u: 1.41 d: 0.9207
u: 1.42 d: 0.9222
u: 1.43 d: 0.9236
u: 1.44 d: 0.9251
u: 1.45 d: 0.9265
u: 1.46 d: 0.9279
u: 1.47 d: 0.9292
u: 1.48 d: 0.9306
u: 1.49 d: 0.9319
u: 1.5 d: 0.9332
u: 1.51 d: 0.9345
u: 1.52 d: 0.9357
u: 1.53 d: 0.9370
u: 1.54 d: 0.9382
u: 1.55 d: 0.9394
u: 1.56 d: 0.9406
u: 1.57 d: 0.9418
u: 1.58 d: 0.9429
u: 1.59 d: 0.9441
u: 1.6 d: 0.9452
u: 1.61 d: 0.9463
u: 1.62 d: 0.9474
u: 1.6300000000000001 d: 0.9485
u: 1.6400000000000001 d: 0.9495
u: 1.6500000000000001 d: 0.9505
u: 1.6600000000000001 d: 0.9515
u: 1.67 d: 0.9525
u: 1.68 d: 0.9535
u: 1.69 d: 0.9545
u: 1.7 d: 0.9554
u: 1.71 d: 0.9564
u: 1.72 d: 0.9573
u: 1.73 d: 0.9582
u: 1.74 d: 0.9591
u: 1.75 d: 0.9599
u: 1.76 d: 0.9608
u: 1.77 d: 0.9616
u: 1.78 d: 0.9625
u: 1.79 d: 0.9633
u: 1.8 d: 0.9641
u: 1.81 d: 0.9649
u: 1.82 d: 0.9656
u: 1.83 d: 0.9664
u: 1.84 d: 0.9671
u: 1.85 d: 0.9678
u: 1.86 d: 0.9686
u: 1.87 d: 0.9693
u: 1.8800000000000001 d: 0.9699
u: 1.8900000000000001 d: 0.9706
u: 1.9000000000000001 d: 0.9713
u: 1.9100000000000001 d: 0.9719
u: 1.92 d: 0.9726
u: 1.93 d: 0.9732
u: 1.94 d: 0.9738
u: 1.95 d: 0.9744
u: 1.96 d: 0.9750
u: 1.97 d: 0.9756
u: 1.98 d: 0.9762
u: 1.99 d: 0.9767
u: 2.0 d: 0.9773
u: 2.0100000000000002 d: 0.9778
u: 2.02 d: 0.9783
u: 2.0300000000000002 d: 0.9788
u: 2.04 d: 0.9793
u: 2.05 d: 0.9798
u: 2.06 d: 0.9803
u: 2.07 d: 0.9808
u: 2.08 d: 0.9812
u: 2.09 d: 0.9817
u: 2.1 d: 0.9821
u: 2.11 d: 0.9826
u: 2.12 d: 0.9830
u: 2.13 d: 0.9834
u: 2.14 d: 0.9838
u: 2.15 d: 0.9842
u: 2.16 d: 0.9846
u: 2.17 d: 0.9850
u: 2.18 d: 0.9854
u: 2.19 d: 0.9857
u: 2.2 d: 0.9861
u: 2.21 d: 0.9864
u: 2.22 d: 0.9868
u: 2.23 d: 0.9871
u: 2.24 d: 0.9875
u: 2.25 d: 0.9878
u: 2.2600000000000002 d: 0.9881
u: 2.27 d: 0.9884
u: 2.2800000000000002 d: 0.9887
u: 2.29 d: 0.9890
u: 2.3000000000000003 d: 0.9893
u: 2.31 d: 0.9896
u: 2.32 d: 0.9898
u: 2.33 d: 0.9901
u: 2.34 d: 0.9904
u: 2.35 d: 0.9906
u: 2.36 d: 0.9909
u: 2.37 d: 0.9911
u: 2.38 d: 0.9913
u: 2.39 d: 0.9916
u: 2.4 d: 0.9918
u: 2.41 d: 0.9920
u: 2.42 d: 0.9922
u: 2.43 d: 0.9925
u: 2.44 d: 0.9927
u: 2.45 d: 0.9929
u: 2.46 d: 0.9931
u: 2.47 d: 0.9932
u: 2.48 d: 0.9934
u: 2.49 d: 0.9936
u: 2.5 d: 0.9938
u: 2.5100000000000002 d: 0.9940
u: 2.52 d: 0.9941
u: 2.5300000000000002 d: 0.9943
u: 2.54 d: 0.9945
u: 2.5500000000000003 d: 0.9946
u: 2.56 d: 0.9948
u: 2.57 d: 0.9949
u: 2.58 d: 0.9951
u: 2.59 d: 0.9952
u: 2.6 d: 0.9953
u: 2.61 d: 0.9955
u: 2.62 d: 0.9956
u: 2.63 d: 0.9957
u: 2.64 d: 0.9959
u: 2.65 d: 0.9960
u: 2.66 d: 0.9961
u: 2.67 d: 0.9962
u: 2.68 d: 0.9963
u: 2.69 d: 0.9964
u: 2.7 d: 0.9965
u: 2.71 d: 0.9966
u: 2.72 d: 0.9967
u: 2.73 d: 0.9968
u: 2.74 d: 0.9969
u: 2.75 d: 0.9970
u: 2.7600000000000002 d: 0.9971
u: 2.77 d: 0.9972
u: 2.7800000000000002 d: 0.9973
u: 2.79 d: 0.9974
u: 2.8000000000000003 d: 0.9974
u: 2.81 d: 0.9975
u: 2.82 d: 0.9976
u: 2.83 d: 0.9977
u: 2.84 d: 0.9977
u: 2.85 d: 0.9978
u: 2.86 d: 0.9979
u: 2.87 d: 0.9979
u: 2.88 d: 0.9980
u: 2.89 d: 0.9981
u: 2.9 d: 0.9981
u: 2.91 d: 0.9982
u: 2.92 d: 0.9983
u: 2.93 d: 0.9983
u: 2.94 d: 0.9984
u: 2.95 d: 0.9984
u: 2.96 d: 0.9985
u: 2.97 d: 0.9985
u: 2.98 d: 0.9986
u: 2.99 d: 0.9986
u: 3.0 d: 0.9987
参考文献:
https://wenku.baidu.com/view/7d60456318e8b8f67c1cfad6195f312b3069eb3e.html
https://wenku.baidu.com/view/ce52a68658fb770bf78a55bb.html