帮助理解确定的积分 [英] Help understanding a definitive integral

查看:89
本文介绍了帮助理解确定的积分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MATLAB和C#将书中的函数转换为代码.

I am trying to translate a function in a book into code, using MATLAB and C#.

我首先试图让该函数在MATLAB中正常工作.

I am first trying to get the function to work properly in MATLAB.

以下是说明:

变量为:

xt and m can be ignored.
zMax = Maximum Sensor Range (100)
zkt = Sensor Measurement (49)
zkt* = What sensor measurement should have been (50)
oHit = Std Deviation of my measurement (5)

我已经在MATLAB中编写了第一个公式N(zkt; zkt *,oHit):

I have written the first formula, N(zkt;zkt*,oHit) in MATLAB as this:

hitProbabilty = (1/sqrt( 2*pi * (oHit^2) ))...
                * exp(-0.5 * (((zkt- zktStar) ^ 2) / (oHit^2))  );

这给了我期望的高斯曲线.

This gives me the Gaussian curve I expect.

下面的定积分有问题,我不明白如何将其转换为实数,因为我从代码中得到了可怕的值,这是这样的:

I have an issue with the definite integral below, I do not understand how to turn this into a real number, because I get horrible values out my code, which is this:

func = @(x) hitProbabilty * zkt * x;
normaliser = quad(func, 0, max) ^ -1;  
hitProbabilty = normaliser * hitProbabilty;

有人可以帮助我解决这个问题吗?它应该使我的曲线归一化,但是会发疯....(我正在针对zkt 0:1:100进行此操作,其他所有条件都相同,并绘制出应该输出的概率图.)

Can someone help me with this integral? It is supposed to normalize my curve, but it just goes crazy.... (I am doing this for zkt 0:1:100, with everything else the same, and graphing the probability it should output.)

推荐答案

您应该使用错误函数 ERF (在基本的MATLAB中可用)

You should use the error function ERF (available in basic MATLAB)

@Jim Brissom 所述,累积分布函数( CDF)通过以下方式与错误功能相关:

As @Jim Brissom mentioned, the cumulative distribution function (CDF) is related to the error function by:

normcdf(X) = (1 + erf(X/sqrt(2)) / 2 ,   where X~N(0,1)

请注意, NORMCDF 需要统计工具箱

Note that NORMCDF requires the Statistics Toolbox

我认为看到这些评论会有些混乱..上面仅计算归一化因子,因此,如果要计算某个值范围内的最终概率,则应执行以下操作:

I think there's been a small confusion seeing the comments.. The above only compute the normalizing factor, so if you want to compute the final probability over a certain range of values, you should do this:

zMax = 100;                         %# Maximum Sensor Range
zktStar = 50;                       %# What sensor measurement should have been
oHit = 5;                           %# Std Deviation of my measurement

%# p(0<z<zMax) = p(z<zMax) - p(z<0)
ncdf = diff( normcdf([0 zMax], zktStar, oHit) );
normaliser = 1 ./ ncdf;

zkt = linspace(0,zMax,500);         %# Sensor Measurement, 500 values in [0,zMax]
hitProbabilty = normpdf(zkt, zktStar, oHit) * normaliser;

plot(zkt, hitProbabilty)
xlabel('z^k_t'), ylabel('P_{hit}(z^k_t)'), title('Measurement Probability')

这篇关于帮助理解确定的积分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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