Find intersection of 2 normal distribution

32 ビュー (過去 30 日間)
Aishwarya Radhakrishnan
Aishwarya Radhakrishnan 2019 年 10 月 16 日
コメント済み: Star Strider 2019 年 10 月 16 日
Hi,
I have 2 normal pdf and I want to find their intersection:
Screen Shot 2019-10-16 at 14.39.05.png
the intersection is between 160 to 170.
I have code as follows:
mu1 = 160;
var1 = 20;
mu2 = 175;
var2 = 15;
yfun = @(mu,var, x)(2*pi*(var))^(-0.5)* exp(-((x-mu).^2)/(2*(var)));
val = fzero(@(x) yfun(mu1, var1, x) == yfun(mu2, var2, x), rand * (mu1 - mu2) + (mu1 + mu2))
Output:
val =
324.6802
Its the value of 2nd parameter of fzero() and fzero() sets val to it's 2nd parameter whatever i change it to.
How do i find the intersection's x value?

採用された回答

Star Strider
Star Strider 2019 年 10 月 16 日
The ‘val’ value is the x-value of the intersection, however you need to start fzero in the correct region for it to return the correct value. It is then straightforward to calculate the y-value from either Gaussian function, since they are both approximately the same at that point.
I changed your code slightly so it returns the correct results:
mu1 = 160;
var1 = 20;
mu2 = 175;
var2 = 15;
yfun = @(mu,var, x)(2*pi*(var))^(-0.5)* exp(-((x-mu).^2)/(2*(var)));
val = fzero(@(x) yfun(mu1, var1, x) - yfun(mu2, var2, x), mean([mu1,mu2]))
yval = yfun(mu1, var1, val)
producing:
val =
167.872647061767
yval =
0.0189439821229373
Experiment to get the result you want.
  3 件のコメント
John D'Errico
John D'Errico 2019 年 10 月 16 日
編集済み: John D'Errico 2019 年 10 月 16 日
Note the importance of how Star used subtraction there instead of using ==. Testing for equality is a bad idea, because it will essentially never happen that they are exactly equal. You want to search for where the difference crosses zero.
Star Strider
Star Strider 2019 年 10 月 16 日
@Aishwarya Radhakrishnan — As always, my pleasure!
@John D’Errico — I very much appreciate your Comment!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by