Value of infinite integral is different
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
John D'Errico
2022-8-8
编辑:John D'Errico
2022-8-8
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 个评论
Alan Stevens
2022-8-8
The value of your integral is infinite! Are you sure you have written the function S correctly?
Torsten
2022-8-8
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!