0

I need to build a matrix with extremely small entries. So far I realized that the fastest way to define the kind of matrix that I need is:

  1. Define a vectorized function of coordinates:

    func = function(m,n){...}
    
  2. Combine every possible coordinate using outer:

    matrix = outer(1:100,1:100,FUN=func)
    

Having to deal with extremely small numbers I work in func's environment using brob numbers, its output will therefore be of the same type of a brob:

typeof(func(0:100,0:100) )
[1] "S4"

If I directly plug two vectors 0:100 in my function func it returns a vector of brobs but if I try to use it with outer I get the error:

Error in outer(1:100, 1:100, FUN = func) : invalid first argument

I suppose this is because package Brobdingnag can somehow deal with vectors but not with matrices. Is it right? Is there any way to make it work?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • 1
    Why don't you work with the logs of your numbers? That is the typical solution if numbers are so small that floating point precision becomes a problem. – Roland Nov 10 '16 at 15:09
  • I need to use this matrix as a set of ordinary differential equations to solve eventually with "expoRkit" or "ode". With logs there's no way to do that and even if I make all calculations with logs and I exponentiate right before producing the output accuracy will be lost either way. – glaudanno Nov 10 '16 at 15:32
  • And these functions support arbitrary precision arithmetics? – Roland Nov 10 '16 at 15:44
  • All that I do is performing sums, multiplications and exponentiation. All of those operations are handled by Brobdingnag package. The only problem is when I try to build a matrix with them using outer. – glaudanno Nov 11 '16 at 12:33

0 Answers0