integral() not working properly?

14 views (last 30 days)
Dyuman Joshi
Dyuman Joshi on 15 Jul 2022
Commented: Dyuman Joshi on 15 Jul 2022
I am trying to integrate a function, however integral() doesn't seem to give the correct value -
f=@(t) sin(t.^3./3);
y=integral(f, 0, Inf)/pi
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 3.4e+29. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
y = -1.0647e+29
Doing symbolic integration
format long
syms x
z=double(int(sin(x^3/3), 0, Inf)/pi)
z =
0.204975542482000
Doing the same in Wolfram Alpha results in the correct answer, I have attached the image file.
Any particular reason why this is happening?

Answers (1)

Chunru
Chunru on 15 Jul 2022
Edited: Chunru on 15 Jul 2022
% This is an oscillating function. It is difficult for numerical
% integration to converge (automatically compute intervals).
% Sometime, one can adjust Tol parameters and integration interval for luck.
f=@(t) sin(t.^3./3);
%y=integral(f, 0, Inf, 'RelTol', 0, 'AbsTol',1e-8)/pi
y=integral(f, 0, (10000*6*pi).^(1/3), 'RelTol', 0, 'AbsTol',1e-8)/pi
y = 0.2049
% The symbolic integration is evaluating the formula
format long
syms x
z=double(int(sin(x^3/3), 0, Inf)/pi)
z =
0.204975542482000
  1 Comment
Dyuman Joshi
Dyuman Joshi on 15 Jul 2022
I did see a similar example on the integral()'s documentation page, and I did try to implement tolerances as well but to no avail. You seem to have hit the lucky spot.
So, the intervals mentioned are the value of input for which the integration converges?
Also, the big picture is something different. This was a special case of the function -
f=@(t,x) sin(t.^3./3+x.*t);
It seems quite difficult to proceed for different values of x. Even symbolic integration fails for values of x other than 0.
format long
syms x
z=int(sin(x^3/3+2*x), 0, Inf)/pi
z = 
NaN
z=int(sin(x^3/3-3*x), 0, Inf)/pi
z = 
NaN
Do you have any ideas how to deal with this?

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!