Value of infinite integral is different
4 ビュー (過去 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;
S = @(k) (k.^3).*(1+(2.35.*(k).^(2/3)));
J = integral(S,0,Inf)
l = integral(S,0,1000000000000000000000000000000000000000000000000000000000000000000)
回答 (3 件)
John D'Errico 2022 年 8 月 8 日
編集済み: John D'Errico 2022 年 8 月 8 日
First, What is the correct value of this integral?
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.
SURPRISE! MATLAB agrees with me.
But then you tried integral. Did integral tell you the value was REALLY, REALLY big?
Kfun = matlabFunction(K);
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?
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.
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 2022 年 8 月 8 日
The value of your integral is infinite! Are you sure you have written the function S correctly?