【问题标题】:MATLAB - Calculate overlapping area of two distributionsfMATLAB - 计算两个分布的重叠面积f
【发布时间】:2021-10-20 19:48:11
【问题描述】:

我想在 MATLAB 中找到两个分布之间的重叠区域。我在 Python (Calculate overlap area of two functions) 中找到了一个解决方案,但不幸的是我被困在使用 MATLAB 来解决这个问题。

这是两个简单正态分布(y1,y2)的示例。我想计算这些分布之间的重叠面积。

        x = linspace(-15, 15); 
        y1 = normpdf(x, -5, 2.7)*5000;     
        y2 = normpdf(x, +5, 2.9)*5500;
        
        % PLOT
        plot(x, y1)
        hold on
        plot(x, y2) 

Image of overlapping distributions

【问题讨论】:

    标签: matlab statistics distribution area


    【解决方案1】:

    如您所见和this answer 中所示,您要计算的面积是 min(y1,y2) 的积分

    首先创建向量y,它是一个1x100 double 向量,就像y1y2 一样。

    y=min(y1,y2)
    

    那么基于Riemann sum的概念,你应该计算向量y的每个元素下的区间长度。由于代码linspace(-15, 15) 第一行中的linspace 函数将一个长度为30 的区间划分为100 部分,那么区间将是:

    IntevalLength = (15-(-15))/size(y,2)
    

    所以Riemann integral 中每个矩形的面积将计算为:

    AreaOfRectangles = IntevalLength * y;
    

    AreaOfRectangles 的总和将为您提供照片中绿色部分的面积。

    >> sum(AreaOfRectangles)
    
    ans =
    
      385.6763
    

    【讨论】:

      猜你喜欢
      • 2013-12-21
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      • 2016-05-05
      相关资源
      最近更新 更多