"Teja Muppirala" wrote in message <klddfh$at0$1@newscl01ah.mathworks.com>...
> TRAPZ works by summing things assuming unit step size in the xdirection. So you need to scale the answer by "dx" to get the right answer, or you can call TRAPZ(x,y) and it will do the appropriate scaling for you.
>
> The area of the intersection is basically the area under the minimum of the two curves.
> So you could define a function that returns the minimum of the two curves, then evaluate that and call TRAPZ, or you could use INTEGRAL (for newer versions) or QUADGK (for older versions).
>
> With the code below, I get an answer of 0.0593 either way, and that seems reasonable.
>
> mx256m = [17747.998047,17859.041016,17474.904297,16872.554688,18829.910156,19107.115234,17471.216797,19600.185547,18658.857422,17313.257812];
> imp = [43974.179688,28197.365234,48259.617188,35682.351562,38330.378906,29280.316406,23040.587891,22871.777344];
>
> figure('Color',[1 1 1]);
> x = 50000:0.1: 14000;
>
> mu256=mean(mx256m);
> sigma256=std(mx256m);
> Y256pdf=normpdf(x,mu256,sigma256);
> plot(x,Y256pdf,'r','LineWidth',2);
> hold;
>
> muimp=mean(imp);
> sigmaimp=std(imp);
> Yimppdf=normpdf(x,muimp,sigmaimp);
> plot(x,Yimppdf,'g','LineWidth',2);
>
> % Define a function to be the minimum of the two curves
> F = @(x) min( normpdf(x,mu256,sigma256) ,normpdf(x,muimp,sigmaimp) );
> area(x,F(x),'linewidth',2); %Draw the shaded area
> x_int= 50000:0.1:0; % Just in case, take a wider region that you need
> trapz(x_int,F(x_int)) % Call TRAPZ with 2 inputs, so the scaling is applied correctly
> integral(F,50000,0) %< Also works
Firstly Teja, thank you so much for your response.
Both trapz and integral are, as you said, returning the same figure.
Can you tell me, if I want to split the area under the curve and calculate the area would the code below make sense?
What I think I am doing is calculating the area to the left of the xcoordinate value 18000 and then the area to the right of that value?
...or am I just dillusional?
x_int= 50000:0.1:18000;
trapz(x_int,F(x_int))
x_int= 18000:0.1:0;
trapz(x_int,F(x_int))
