# Use Logs to deal with very large numbers in MATLAB

• Dec 10th 2011, 10:37 AM
xlxc34
Use Logs to deal with very large numbers in MATLAB
Hi,

I'm not entirely sure I'm posting this in the right place as I'm an engineer not a mathmatician, but it's certainly harder than anything I had to do to get my maths A-level before I went to University!

I'm using the equation below to model cracks forming in a polymer under stress. My problem is this: k (the Boltzmann constant, 1.38 x 10^23... pretty small) is part of the exponential terms. The other variables are more manageable; U is around 1.14 x 10^5, and gamma is around 3.56 x 10^-4. Sigma is the effective stress, and would be around 10^7 Pa or thereabouts. T is the absolute temperature and is about 293K. n(t) is the time at which the polymer becomes macroscopically damaged.

Attachment 23057

I'm working with MATLAB, which is limited by the IEEE 'double' precision. This means it can deal with numbers up to about 1.7*10^308. Unfortunately, if you try and perform exp(-U/kT), -U/kT is about -2 x 10^25, so MATLAB returns 0. Similarly, for exp(gamma.sigma/kT) it returns infinity. I'm sure it is possible to rescale the problem somehow or work in logs to get around this but I can't figure out how you'd do this. Can anyone offer any help on this? It will be much appreciated!

Thanks,

Pete
• Dec 11th 2011, 06:42 AM
CaptainBlack
Re: Use Logs to deal with very large numbers in MATLAB
Quote:

Originally Posted by xlxc34
Hi,

I'm not entirely sure I'm posting this in the right place as I'm an engineer not a mathmatician, but it's certainly harder than anything I had to do to get my maths A-level before I went to University!

I'm using the equation below to model cracks forming in a polymer under stress. My problem is this: k (the Boltzmann constant, 1.38 x 10^23... pretty small) is part of the exponential terms. The other variables are more manageable; U is around 1.14 x 10^5, and gamma is around 3.56 x 10^-4. Sigma is the effective stress, and would be around 10^7 Pa or thereabouts. T is the absolute temperature and is about 293K. n(t) is the time at which the polymer becomes macroscopically damaged.

Attachment 23057

I'm working with MATLAB, which is limited by the IEEE 'double' precision. This means it can deal with numbers up to about 1.7*10^308. Unfortunately, if you try and perform exp(-U/kT), -U/kT is about -2 x 10^25, so MATLAB returns 0. Similarly, for exp(gamma.sigma/kT) it returns infinity. I'm sure it is possible to rescale the problem somehow or work in logs to get around this but I can't figure out how you'd do this. Can anyone offer any help on this? It will be much appreciated!

Thanks,

Pete

First thing to do is combine those two exponentials and see if you still overflow the exponentiation.

CB
• Dec 11th 2011, 10:19 AM
xlxc34
Re: Use Logs to deal with very large numbers in MATLAB
Thanks for the reply... I think I might be quite close to achieving it using logs. I'm trying it with all the variables set to near 1 so it doesn't throw up such crazy numbers just to test it out, but I'm having trouble expanding a big set of brackets.

say I want take the log of both sides of this equation:

Z=-A*exp(-B)*exp(C)*(D*exp(E)-D*exp(F));

I know that to take the log of a series of terms multiplied together you do for example

log(A*B*exp(C)*D)=log(A)+log(B)+C+log(D)

What I have is effectively

Z=exp(A*exp(B)*exp(C)*D*exp(E*t2)-A*exp(B)*exp(C)*D*exp(E*t1));
logZ=A*exp(B)*exp(C)*D*exp(E*t2)-A*exp(B)*exp(C)*D*exp(E*t1);
loglogZ=?

So yeah, how do I take the log of two numbers added together?

Thanks again for your help, I will hopefully be able to resolve this tomorrow when I'm able to access my trusty copy of Engineering Mathmatics by Stroud but just in case there isn't anything in there I'd like to get it worked out!