numerical partial derivative in MatLab

前端 未结 2 1797
旧时难觅i
旧时难觅i 2020-12-12 01:07

How can I compute the numerical partial derivative of a probability density function (PDF) in Matlab? I\'m not looking for a solution using automatic differences or a symbol

相关标签:
2条回答
  • 2020-12-12 01:29

    My understanding is that arg and mu are constant and sigma varies. This is an obvious approximation:

    arg = 0;
    mu = 0;
    incr = 0.0001;
    sigma = incr:incr:1.5;
    
    f = normpdf(arg,mu,sigma);
    d = diff(f) / incr;
    plot(sigma(2:end), d, '.')
    set(gca, 'XLim', [0.05 1.5])
    
    0 讨论(0)
  • 2020-12-12 01:47

    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;
    

    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;
    

    This technique is fast, simple, and very accurate. You can download this as a convenient function, cdiff, from my GitHub.

    0 讨论(0)
提交回复
热议问题