MATLAB: Use $integral $ and $fzero$ with ksdensity

fzerointegrationksdensitypdf

Hello, I have been looking for finding the intersection of two outputs of ksdensity, as well as integrating the difference of the two questions. Can you please see the code, you might understand what I am trying to say:
xlsread('Sheet1.xlsx','Hourly Data','B:B'); % load Data
Load = xlsread('Sheet1.xlsx','Hourly Data','D:D'); %load Data
[f_re,xr] = ksdensity(RE); % to return the 1st pdf
[f_lo,xl] = ksdensity(Load); %returns the 2nd pdf
figure
plot(xl,f_lo,xr,f_re); % plot
f1=@(x) f_re(x); % and starting from this line , things are getting complicated
f2=@(x) f_lo(x);
Pl=fzero(f1-f2,0); % trying to find the intersections of the two functions may be
q = integral(f1-f2,0,inf); % integrating the difference ?
And obviously, Matlab does return errors. I do not know how to do all of this, Could you please give me some hints! Thank you so much.

Best Answer

Pl=fzero(@(x) f1(x)-f2(x),0); % trying to find the intersections of the two functions may be
q = integral(@(x) f1(x)-f2(x),0,inf); % integrating the difference ?
You cannot add or subtract function handles: you have to call the function handles with arguments and add or subtract the results.
Related Question