Multiplication of large number with small number

15 views (last 30 days)
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
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!
Filip Trönnberg
Filip Trönnberg on 10 May 2012
Was my first thought too but unfortunately bessel(u>28) is evaluated as inf.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 9 May 2012
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.
Filip Trönnberg
Filip Trönnberg on 10 May 2012
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!

Sign in to comment.

More Answers (1)

John D'Errico
John D'Errico on 9 May 2012
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.
John D'Errico
John D'Errico on 10 May 2012
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!