Value of infinite integral is different
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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)
l = integral(S,0,1000000000000000000000000000000000000000000000000000000000000000000)
0 Kommentare
Antworten (3)
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)))
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])
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)
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)
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
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
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.
0 Kommentare
Alan Stevens
am 8 Aug. 2022
The value of your integral is infinite! Are you sure you have written the function S correctly?
Torsten
am 8 Aug. 2022
syms k
S = k^3*(1+2.35*k^(2/3));
J = int(S,k)
J1 = subs(J,k,Inf)
J2 = subs(J,k,sym('1000000000000000000000000000000000000000000000000000000000000000000'))
0 Kommentare
Siehe auch
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!