Value of infinite integral is different

1 Ansicht (letzte 30 Tage)
Athira T Das
Athira T Das am 8 Aug. 2022
Bearbeitet: John D'Errico am 8 Aug. 2022
I am trying to evaluate integral of a function which is from 0 to infinity. And I evaluated the function in two ways, i.e. 0 to Inf anf 0 to a large number.
And the values of this two methods is entirely different and difference is huge.
Can someone help me to find the reason and which ansewer is right.
clc; clear all; close all;
syms k
S = @(k) (k.^3).*(1+(2.35.*(k).^(2/3)));
J = integral(S,0,Inf)
Warning: Minimum step size reached near x = 3.24519e+30. There may be a singularity, or the tolerances may be too tight for this problem.
J = 1.3907e+147
l = integral(S,0,1000000000000000000000000000000000000000000000000000000000000000000)
l = 5.0357e+307

Antworten (3)

John D'Errico
John D'Errico am 8 Aug. 2022
Bearbeitet: John D'Errico am 8 Aug. 2022
First, What is the correct value of this integral?
syms k
K = (k.^3).*(1+(2.35.*(k).^(2/3)))
K = 
Just looking at it, I see a function that goes to infinity, as k approaches infinity. So I know the value is itself undefined. I need not even compute the result. I'll let MATLAB tell me that though, just for kicks. This IS a question about MATLAB, after all.
int(K,[0,inf])
ans = 
SURPRISE! MATLAB agrees with me.
But then you tried integral. Did integral tell you the value was REALLY, REALLY big?
Kfun = matlabFunction(K);
integral(Kfun,0,inf)
Warning: Minimum step size reached near x = 3.24519e+30. There may be a singularity, or the tolerances may be too tight for this problem.
ans = 1.3907e+147
Does it matter exactly how close to infinity it gets, when the number is that big? NO. What did integral tell you? It thought there was a problem, one that it could not resolve. It essentially gave up at that point.
When you tried this:
l = integral(Kfun,0,1000000000000000000000000000000000000000000000000000000000000000000)
l = 5.0357e+307
Do you recognize that the result it returned is pretty close to the biggest double precision number MATLAB can generate, that is not quite an overflow?
realmax
ans = 1.7977e+308
You probably need to think about what numbers you can store in a double, and using double precision arithmetic. That is certainly the case when you try to use upper limits like 1e66 for an integral.
1000000000000000000000000000000000000000000000000000000000000000000
ans = 1.0000e+66
You probably also need to learn about how to enter large numbers like that anyway. But not for this problem.
When you see a warning message like the one integral returned, think about if there may be a numerical problem, and what is the likely issue. The issue here is the integral is undefined. It has no finite value, however, integral cannot return an infinite result. the syms tool int CAN see the result is best described as inf, and does return that result.

Alan Stevens
Alan Stevens am 8 Aug. 2022
The value of your integral is infinite! Are you sure you have written the function S correctly?

Torsten
Torsten am 8 Aug. 2022
syms k
S = k^3*(1+2.35*k^(2/3));
J = int(S,k)
J = 
J1 = subs(J,k,Inf)
J1 = 
J2 = subs(J,k,sym('1000000000000000000000000000000000000000000000000000000000000000000'))
J2 = 

Kategorien

Mehr zu Performance and Memory finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by