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
  • 49,445
  • 7
  • 57
  • 113
QuestionEverything
  • 4,419
  • 6
  • 38
  • 60

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,668
  • 10
  • 69
  • 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
  • 49,445
  • 7
  • 57
  • 113