Looks like a machine error

9 Ansichten (letzte 30 Tage)
Kwame Atta Gyamfi
Kwame Atta Gyamfi am 10 Jan. 2020
Beantwortet: Steven Lord am 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.

Akzeptierte Antwort

Steven Lord
Steven Lord am 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

Weitere Antworten (0)

Kategorien

Mehr zu Function Creation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by