Multiplication of large number with small number

6 次查看(过去 30 天)
I'm trying to compute a rather ugly integral using MATLAB. What I'm having problem with though is a part where I multiply a very big number (>10^300) with a very small number (<10^-300). MATLAB returns 'inf' for this even though it should be in the range of 0-0.0005. This is what I have
besselFunction = @(u)besseli(qb,2*sqrt(lambda*(theta + mu)).*u);
exponentFuncion = @(u)exp(-u.*(lambda + theta + mu));
where qb = 5, lambda = 12, theta = 10, mu = 3. And what I want to find is
besselFunction(u)*exponentFunction(u)
for all real values of u. The problem is that whenever u>28 it will be evaluated as 'inf'. This is because the besselFunction(29) is so large even though exponentFunction(29) is extremely small. I've heared of, and tried, to use MATLAB function 'vpa' but it doesn't seem to work well when I want to use functions...
Any tips will be appreciated at this point!
  2 个评论
laurie
laurie 2012-5-9
sorry i feel stupid for even suggesting this, but can't you divide your very large number bessel(u>28) by, say, 10^150, do your multiplication, and then multiply 10^150 again after that ? or is bessel (u>28) evaluated as 'inf' ?
Filip Trönnberg
Filip Trönnberg 2012-5-10
Was my first thought too but unfortunately bessel(u>28) is evaluated as inf.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2012-5-9
vpa() is for use with symbolic expressions only.
If you have the symbolic engine,
besselFunction = @(u)besseli(qb,2*sqrt(lambda*(theta + mu)).*sym(u));
exponentFuncion = @(u)exp(-sym(u).*(lambda + theta + mu));
Then besselFunction(u)*exponentFunction(u) will return a symbolic value. You can double() it if you want the double-precision representation.
Note: going symbolic will only postpone the problem: the symbolic engine is limited to about a billion decimal places.
  3 个评论
Walter Roberson
Walter Roberson 2012-5-9
The dynamic range for symbolic numbers only goes up to somewhere around 10 to 1 billion.
Filip Trönnberg
Filip Trönnberg 2012-5-10
Great suggestion, thanks! It is correct that the symbolic numbers could pose a limitation but for my needs it was more than enough. What John wrote do also work but requires some extra thinking!

请先登录,再进行评论。

更多回答(1 个)

John D'Errico
John D'Errico 2012-5-9
The simple answer is always to use logs. The log of these numbers will be well behaved. Add the logs, then exponentiate at the end.
You could also use my HPF toolbox. It is now on the FEX, although I've not yet implemented bessel functions.
And, of course, the symbolic toolbox is an option with vpa.
  3 个评论
Sargondjani
Sargondjani 2012-5-9
he means: take logs, add them, take exponential. this is equivalent to multipying 2 numbers:
a x b = exp (log (a x b)) = exp(log a + log b)
John D'Errico
John D'Errico 2012-5-10
Exactly as Sargondjani says. A problem may be you need the log of this bessel function, if it is itself too large for the dynamic range of a double. For that you might need to use some approximations. Perhaps a series approximation would be adequate for the log of the bessel function. Or, one day I'll get bessel functions written for HPF, or maybe someone else will do that.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by