Asked by alex corno
on 4 Jun 2013

I'm using expm for a matrix with big and small coefficients and I get NaN in the result. Is there a method to get the good matrix exponential even if the matrix is badly scaled? Normally there is a exponential for every matrix.

ALEX

Answer by Richard Brown
on 5 Jun 2013

Accepted Answer

You might this Cleve's corner instructive http://blogs.mathworks.com/cleve/2012/07/23/a-balancing-act-for-the-matrix-exponential/

In particular, have you tried the alternative versions expmdemo1 and expmdemo3 ?

Sign in to comment.

Answer by Matt J
on 4 Jun 2013

Edited by Matt J
on 4 Jun 2013

I think I have a different problem. My matrix isn't even invertible, there are two zero lines, moreover there are some coefficients that are of order of 1e6. In my opinion at some point Matlab is doing some inversion that's why expm doesn't work properly with badly scaled matrices.

No, it's not an invertibility issue. The reason for the NaNs is the big 1e6 order numbers. Below is an example of a non-invertible matrix on which EXPM works fine.

>> expm(diag([1,0]))

ans =

2.7183 0

0 1.0000

Matt J
on 4 Jun 2013

Conversely, just by multiplying this matrix by 1e6,

>> expm(diag([1e6,0]))

ans =

NaN NaN

NaN NaN

alex corno
on 4 Jun 2013

Matt J
on 4 Jun 2013

Even if the matrix is well-scaled, you could have the same problem, for example:

>> A=diag([1e6,1e6]); %a well-scaled matrix

>> expm(A)

ans =

NaN NaN

NaN NaN

The bottom line is, you must avoid matrices with large eigenvalues, and then things should be fine. Otherwise, they will not be fine.

There are any number of transformations you could consider to reduce the magnitude of the eigenvalues. Dividing the matrix by a large number is one way, but I can't know if that suits your application.

Sign in to comment.

Answer by alex corno
on 5 Jun 2013

Thank you for your help. I think the function balance() is what I was looking for.

Alexandru

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Matt J (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/77906-how-to-calculate-expm-of-a-badly-scaled-matrix#comment_152749

## alex corno (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/77906-how-to-calculate-expm-of-a-badly-scaled-matrix#comment_152772

Sign in to comment.