更新时间:2021-10-20 01:00:47
我认为实际功能不是正态分布的PDF.如果您仅尝试使用复杂步阶需要一阶导数:
I assume that the actual function is not the PDF of the normal distribution. You might try using complex step differentiation if you only need the first derivative:
mu = 0;
sigma = 0.5;
f = @(x)normpdf(x,mu,sigma);
x = -1:0.01:1;
h = 2^-28;
dx = imag(f(x+1i*h))/h;
或者如果您将x
和mu
保持不变并更改sigma
:
Or if you hold x
and mu
constant and vary sigma
:
mu = 0;
x = 0;
g = @(sigma)normpdf(x,mu,sigma);
sigma = 0.25:0.01:0.75;
h = 2^-28;
dsigma = imag(g(sigma+1i*h))/h;
此技术快速,简单且非常准确.您可以从我的GitHub下载 cdiff
作为便捷功能.
This technique is fast, simple, and very accurate. You can download this as a convenient function, cdiff
, from my GitHub.