-2

Does anyone have a method to generate a logarithmically spaced number array. The method signature would be:

public static List<double> logSpace (double start, double end, double numValues)

This is similar to matlab function 'logspace'

mcintoda
  • 635
  • 1
  • 8
  • 10

1 Answers1

4

I'm not familiar with matlab, but it sounds like you're looking for something like this:

public IEnumerable<double> logspace(double start, double end, int count)
{
    double d = (double)count, p = end/start;
    return Enumerable.Range(0, count).Select(i => start * Math.Pow(p, i/d));
}

logspace(0.1, 1, 10); // 0.1, 0.13, 0.16, 0.2, 0.25, 0.32, 0.4, 0.5, 0.63, 0.79
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331