Discontinuities when computing integration of error functions using integral function

I am trying to integrate a function over a region in different time intervals. The integration looks something like this.
fun_uz = @(u)1./sqrt(u).*exp(-Z.^2./(2.*u));
fun_Y = @(u)(erf((Y+B)./sqrt(2.*u))-erf((Y-B)./sqrt(2.*u)));
fun_Z = @(u)(erf((X+L+u)./sqrt(2.*u))-erf((X-L+u)./sqrt(2.*u)));
fun = @(u)inc.*fun_uz(u).*fun_Y(u).*fun_Z(u);
fint = integral(fun,0,upperl);
The variable 'upperl' is the upper limit of the integral function. I have to perform this integration over different X,Y, and Z regions and different 'upperl' values. I am getting profiles which are discontinuous for different 'upperl' values. I have shown here profiles at few different 'upperl' values.
I am not able to understand why the discontinuity are occuring, any help is greatly appreciated. Thanks.

6 件のコメント

darova
darova 2020 年 3 月 19 日
Attach the whole code
Yaswanth  Sai
Yaswanth Sai 2020 年 3 月 19 日
編集済み: Yaswanth Sai 2020 年 3 月 20 日
%%
I changed line
xs = (-10:1:10)./1000;
Looks ok
Yaswanth  Sai
Yaswanth Sai 2020 年 3 月 19 日
編集済み: Yaswanth Sai 2020 年 3 月 19 日
Sorry, I forgot to mention, the plots look continuous for the range I have given in the code. They seem to be discontinuous for very large values of 'xs' as shown in the plots I have posted above. For example, for the values mentioned below, the plot is very discontinuous.
xs = (-500:10:10)./1000;
time = 5*10^(-1);
time = 1e-2; % The variable which is changed to generate different contour plots
xs = (-500:10:10)./1000;
Yaswanth  Sai
Yaswanth Sai 2020 年 3 月 19 日
Yeah, the code works for smaller time values of order 10^(-2) and lesser, but is not working for values greater than that of order 10^(-1) and higher.

サインインしてコメントする。

 採用された回答

darova
darova 2020 年 3 月 19 日
The function you are trying to integrate looks like following
Put these lines inside for loops
ezplot(fun,[0 upperl])
pause(0.01)
When time > 0.1 upperl is big. When you call integral you don't know how many points it takes. Maybe it misses something

5 件のコメント

Yaswanth  Sai
Yaswanth Sai 2020 年 3 月 20 日
Thank you very much. I understood what you are saying. Is there anything you suggest me to do? I was thinking of subdiving the entire interval until it finds a nonzero value. But this approach does not seem to be computationally efficient.
Walter Roberson
Walter Roberson 2020 年 3 月 20 日
Use the waypoints option of integral() if you can.
Yaswanth  Sai
Yaswanth Sai 2020 年 3 月 20 日
Yeah, I tried that. The waypoints seem to vary for different values of 'xs'. So I need to figure out a way to assign the limits. Anyways thank you for the suggestion.
Walter Roberson
Walter Roberson 2020 年 3 月 20 日
I do not see the whole code posted ?
Yaswanth  Sai
Yaswanth Sai 2020 年 3 月 20 日
I added the edited code

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 3 月 20 日
Change the integral to
fint = integral(fun,0,upperl, 'waypoints', L-X);
You have two erf that only have an input near 0 (and so a measurable output) near-ish -(X+L) to -(X-L) . Some of your integral() calls just happened to evaluate near there, and some of them did not happen to evaluate near there and predicted that there was nothing interesting in that area. The above forces evaluation near that area.

1 件のコメント

Yaswanth  Sai
Yaswanth Sai 2020 年 3 月 20 日
編集済み: Yaswanth Sai 2020 年 3 月 20 日
Thank you. I have also used a similar approach to get rid of the discontinuities. I used the following code,
fint = integral(fun,0,upperl,'Waypoints',[abs(X)-abs(X)/2,abs(X)+abs(X)/2]);
Both the approaches are working.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2020 年 3 月 19 日

編集済み:

2020 年 3 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by