How to get a very small value rather than 0?

14 views (last 30 days)
Lorenzo
Lorenzo on 19 Nov 2012
Dear all; I'm trying to work out a script which should give a ver small value as a result. The problem is that I keep getting 0 instead…
Any help would be really appreciated.
Here's the script:
rho=7860;
B=-1.00000000011701;
BL=23.562;
Bj=46.9362549800797;
k=1;
int1(k)=(exp(-2*BL(k))*(2*exp(2*BL(k))*sin(2*BL(k))+(-4*exp(3*BL(k))-4*exp(BL(k)))*sin(BL(k))+(4*exp(BL(k))-4*exp(3*BL(k)))*cos(BL(k))+exp(4*BL(k))+8*BL(k)*exp(2*BL(k))-1))/(8*Bj(k));
int2(k)=-(exp(-2*BL(k))*(2*exp(2*BL(k))*sin(2*BL(k))+(4*exp(3*BL(k))+4*exp(BL(k)))*sin(BL(k))+(4*exp(BL(k))-4*exp(3*BL(k)))*cos(BL(k))-exp(4*BL(k))+1))/(8*Bj(k));
int3(k)=-(exp(-BL(k))*((exp(2*BL(k))-1)*sin(BL(k))-exp(BL(k))*((exp(BL(k))+exp(-BL(k)))/2)^2+exp(BL(k))*cos(BL(k))^2))/(2*Bj(k));
m_cap1=rho.*(int1+B.^2.*int2+2.*B.*int3);

Answers (2)

Matt J
Matt J on 19 Nov 2012
Edited: Matt J on 19 Nov 2012
You haven't said what variable in your code is the problematic one.
Regardless, computers are inevitably discrete things. If you get too close to 0, then the number will have to get rounded to zero in order to be represented in floating point.
  2 Comments
Matt Fig
Matt Fig on 21 Nov 2012
Lorenzo Lore comments:
Sorry, the variable is m_cap1
Matt J
Matt J on 21 Nov 2012
Edited: Matt J on 21 Nov 2012
If Matt Fig's suggestion doesn't work for you (because you don't have the Symbolic Toolbox), then there is this and
and others like it on the FEX.
However, it would be wise to re-evaluate your approach. It looks very dubious to be working with numbers as huge as
>> exp(4*BL)
ans =
8.5386e+40
and still requiring precision<1.

Sign in to comment.


Matt Fig
Matt Fig on 19 Nov 2012
Use the symbolic toolbox if you need more precision than double.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!