How to get a very small value rather than 0?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Matt J
le 19 Nov 2012
Modifié(e) : Matt J
le 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 commentaires
Matt J
le 21 Nov 2012
Modifié(e) : Matt J
le 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.
Matt Fig
le 19 Nov 2012
Use the symbolic toolbox if you need more precision than double.
0 commentaires
Voir également
Catégories
En savoir plus sur MuPAD dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!