How to get a very small value rather than 0?
5 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(2 个)
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 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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 MuPAD 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!