MatLab中的数值偏导数 [英] numerical partial derivative in MatLab

查看:731
本文介绍了MatLab中的数值偏导数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Matlab中计算概率密度函数(PDF)的数字偏导数?我不是在寻找使用自动差异或符号解决方案的解决方案.

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 symbolic solution.

给出以下示例:

arg = (-1:.01:1)';
mu = 0;
sigma = 0.5;

f = normpdf(arg,mu,sigma);

是否可以计算df/dsigma的数值偏导数?还是我不得不使用自动差异或Symbolic Math工具箱?

Is it possible to compute the numerical partial derivative of df/dsigma? Or am I stuck to having to use the automatic differences or the Symbolic Math toolbox?

推荐答案

我认为实际功能不是正态分布的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;

或者如果您将xmu保持不变并更改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.

这篇关于MatLab中的数值偏导数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆