I am running a script in Matlab R2020b. The script contains an array with following values:
a=[500, 500, 500, 1000, 750, 750, 567.79 613.04]
The script as an equation:
(a(1)*(a(8)-a(6)) + a(7)*(a(6)-a(2))+ a(5)*(a(2)-a(8)))
When running on Matlab the above equation gives the answer -11312 for the values of array a. But when I calculate each value separately and add them the Matlab compiler gives a different answer.
a(1)*(a(8)-a(6)) = -68480
a(7)*(a(6)-a(2)) = 1.419e+05
a(5)*(a(2)-a(8)) = -84780
>>(-68480) + (1.419e+05) +(-84780)
the answer for the above is -11310.
A screenshot of the commands is also attached.
kindly tell me why Matlab compiler gives these different answers??