Matlab: How to plot the function $P(x)$ versus $x$, where $P(x)=\int_0^\infty f(y)W(x,y)dy$?

조회 수: 1 (최근 30일)
Erez
Erez 2022년 6월 10일
댓글: Walter Roberson 2022년 7월 14일
In Matlab:
How to plot the function versus x, where
?
I have obtaind the an array of N values for through some (long) numerical calculation, for an array of N values y.
The function has an analytic expression: .
My question is how to plot , which is a function of x defined by this integral over another function of y?
(The ``" is not the problem, of course this can just be set to some large constant, e.g., or , maybe?)
*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?
  댓글 수: 5
Erez
Erez 2022년 6월 13일
@Torsten @Image Analyst@Walter Roberson Guys, thanks for all the ideas, can you show please how to implemet them? -- I haven't been able to understand how to do it myself from the comments :) Maybe it is simple.. but not to me ;)
Torsten
Torsten 2022년 6월 13일
편집: Torsten 2022년 6월 13일
Follow Walter Roberson's hint :
y = (0:10:100).';
x = 3:6;
W = exp(-x.^2./y);
f = @(y)y.^2;
fy = repmat(f(y),1,numel(x));
result = trapz(y,fy.*W)
result = 1×4
1.0e+05 * 2.9353 2.6553 2.3400 2.0112
Can you take it from here ?

댓글을 달려면 로그인하십시오.

답변 (1개)

David Hill
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
Erez
Erez 2022년 7월 14일
@Walter Roberson Very sorry for the long delay. Walter, can you explain pls?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by