Integration for only positive values
이전 댓글 표시
Hi!
I would like to calculate the integral of an already estimated probability density function. This PDF was estimated with a SPLINE, which is "slightly" negative in certain areas. My SPLINE is saved as a "struct" and integrating it works just fine fnint(PDF). However, the resulting CDF is decreasing in those areas of negative densities, which I would like to avoid by simply replacing those areas of the PDF with 0.
My question: Is it possible to set those regions of the function equal to 0, or to integrate just over the positive values ot this PDF? I would like to avoid transforming the function into a vector of resulting densities, and instead use the (spline) function directly?
Thanks in advance!
답변 (2개)
the cyclist
2020년 6월 19일
0 개 추천
Can you just replace your PDF with max(0,PDF) and proceed?
댓글 수: 9
Sim Kron
2020년 6월 19일
the cyclist
2020년 6월 19일
Sorry, I meant my comment to be more conceptual that an exact MATLAB syntax. If you upload the data, it should be possible to give more specific advice.
Walter Roberson
2020년 6월 19일
NNPDF = @(x) max(0, PDF(x))
Unless your PDF is symbolic. If it is symbolic then
NNPDF = symfun(piecewise(PDF(x) < 0, 0, PDF(x)),x)
Sim Kron
2020년 6월 19일
the cyclist
2020년 6월 19일
In the "Insert" section, there is an icon that looks like a paper-clip, that can be used to upload files. Uploading both code and data is usually helpful.
Sim Kron
2020년 6월 19일
Sim Kron
2020년 6월 19일
the cyclist
2020년 6월 19일
It wasn't clear to me which field of the structure you need to modify, but for example if it is coefs,then
PDF.coefs = max(PDF.coefs,0)
Sim Kron
2020년 6월 19일
How to integrate over the positive part of the function
lower_limit=-5; %Lower Limit of the integration
upper_limit=5; %Upper limit of the integration
Point_number=1000; %NUmber of points to be in the function
x_range=linspace(lower_limit,upper_limit,Point_number);
% Enter Function
syms x
f(x)=x^2+3*x-5
y=f(x_range); %Getting function values
y_plus=subplus(y); %Getting only the Positive part
fprintf("Integration of the Positive Part %f",trapz(y_plus))
%more plots
figure
plot(x_range,y_plus,"g","LineWidth",2);
hold on
plot(x_range,y,"r","LineWidth",1);
hold off
legend({'Positive Part','Input Function'});
xline(0);
yline(0);
title("Function")
카테고리
도움말 센터 및 File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
