# Multiplication of large number with small number

15 views (last 30 days)

Show older comments

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!

### Accepted Answer

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.

### More Answers (1)

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.

##### 3 Comments

John D'Errico
on 10 May 2012

### See Also

### Community Treasure Hunt

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

Start Hunting!