0

I know there exists MATLAB functions for log and log2, and for matrix logarithm there is logm. But I was wondering how do I calculate matrix logarithm for base 2?

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
QuestionEverything
  • 4,809
  • 7
  • 42
  • 61

2 Answers2

2

it's just a change-of-base to convert the base of the logarithm, you can just use logm as follows:

log2m=logm(M) ./ log(2);
bla
  • 25,846
  • 10
  • 70
  • 101
2

For a scalar x,

log2(x) = log(x)/log(2)

I see no reason why this wouldn't work with matrix logarithms: logm(m)/log(2).

For example, let's take the matrix from this example on Wikipedia:

issimilar = @(x,y) all( abs(x(:)-y(:)) < 1e-14 );

m = [1.25, 0.75; 0.75, 1.25];

issimilar( exp(1)^logm(m), m ) % returns true
issimilar( 2^(logm(m)/log(2)), m ) % also returns true
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120