How to get a very small value rather than 0?

2 ビュー (過去 30 日間)
Lorenzo
Lorenzo 2012 年 11 月 19 日
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);

回答 (2 件)

Matt J
Matt J 2012 年 11 月 19 日
編集済み: Matt J 2012 年 11 月 19 日
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 件のコメント
Matt Fig
Matt Fig 2012 年 11 月 21 日
Lorenzo Lore comments:
Sorry, the variable is m_cap1
Matt J
Matt J 2012 年 11 月 21 日
編集済み: Matt J 2012 年 11 月 21 日
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.

サインインしてコメントする。


Matt Fig
Matt Fig 2012 年 11 月 19 日
Use the symbolic toolbox if you need more precision than double.

カテゴリ

Help Center および File ExchangeMuPAD についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by