Looks like a machine error
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Kwame Atta Gyamfi
le 10 Jan 2020
Réponse apportée : Steven Lord
le 10 Jan 2020
Dear all,
I need help with a tiny section of a code which involve a basic computation(seemingly):
The following operation,
>> ((-0.085 - -0.1)/(-0.085 - -0.098))*0.6 -(0.005/(-0.085 - -0.098))
gives
>> 0.3077
However, when I replace the figures with variables as below:
>> ((xp32 - xp12new)/(xp32next - xp12next))*U(tn,j+1)-(Dt/(xp32next - xp12new))
Here the variables have equal values of the figures in the preceeding operation.
I get a wierd answer:
>> 0.3590
I don't know what I'm missing here. Thanks in advance.
0 commentaires
Réponse acceptée
Steven Lord
le 10 Jan 2020
Your variables appear to contain the same values as the hard-coded constants, but looks can be deceiving. The small differences between the variable values and the constant values (which don't appear using the default display format but still exist in the stored values) result in the different answer.
You can check this by subtracting the constant values from the variables and noting that you receive a non-zero value.
xp32 - (-0.085) % Not exactly 0, but very small
You can also check this by changing the display format.
format longg
xp32 % not exactly -0.0085
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Function Creation 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!