Matlab: How to plot the function $P(x)$ versus $x$, where $P(x)=\int_0^\infty f(y)W(x,y)dy$?
조회 수: 1 (최근 30일)
이전 댓글 표시
In Matlab:
How to plot the function
versus x, where
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1028030/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1028035/image.png)
I have obtaind the an array of N values for
through some (long) numerical calculation, for an array of N values y.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1028040/image.png)
The function
has an analytic expression:
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1028045/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1028050/image.png)
My question is how to plot
, which is a function of x defined by this integral over another function of y?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1028030/image.png)
(The ``∞" is not the problem, of course this can just be set to some large constant, e.g.,
or
, maybe?)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1028060/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1028065/image.png)
*To emphasize: I know how this can be done using a loop for each value of x : for every x, I can calculate P(x)=trapz(y,f(y)W(x,y)) (~not written in Matlab code).
But, can this be done without a loop?
답변 (1개)
David Hill
2022년 6월 13일
y=1:.01:5;
x=0:.01:7;
[X,Y]=meshgrid(x,y);
W=exp(-X.^2./Y);
f=y.^2;%as an example
I=trapz(W.*f')/.01;%each column of I is the integral at each corresponding x value
댓글 수: 3
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!