Hi, I"m calculating the amount of squares in C and MATLAB in solitary precision and listed some differences. Ns wondered if anyone have the right to fill me in ~ above the action below. Suspect floating allude associative problem, however still appears a tiny odd...

You are watching: Matlab sum of squares

Numbers in my array a are "reasonably" fine scaled, from a obelisk in a single precision matrix produced by MATLAB. Distinctions being seen right here are common and also leading to substantial differences in between same algorithm in C and also MATLAB.

a = single(<-0.112033270,0.153425455,-0.751111090,-0.129932076,0.206365064,-0.871111095,0.000000000,...

https://www.princetoneclub.org/matlabcentral/answers/85148-differences-calculating-the-sum-of-squares-in-single-between-sum-and-a-loop#comment_165124

Single precision floating point numbers have only 24 bits in their significands (mantissas), for this reason you have to expect errors that the stimulate of 1 component in 2^24 or 2^23, or around seven decimal place accuracy. That"s around what I check out in your results. Why does that surprised you?

https://www.princetoneclub.org/matlabcentral/answers/85148-differences-calculating-the-sum-of-squares-in-single-between-sum-and-a-loop#comment_165126

https://www.princetoneclub.org/matlabcentral/answers/85148-differences-calculating-the-sum-of-squares-in-single-between-sum-and-a-loop#comment_165176

Those results can be various if in the an initial case the computer system does the squaring and including all in dual precision before rounding back to solitary precision, when in the 2nd case together a rounding can occur both after ~ the squaring operation and also after the addition.

These single precision outcomes differ only in their` least bit. The takes only one rounding difference among the fifty-one measures to produce that.

https://www.princetoneclub.org/matlabcentral/answers/85148-differences-calculating-the-sum-of-squares-in-single-between-sum-and-a-loop#comment_165195

OK I have actually simplified the difficulty to 2 elements. New simplified inquiry posed: http://www.princetoneclub.org/matlabcentral/answers/85211-different-results-between-2013a-32bit-and-64bit-in-single-precision

https://www.princetoneclub.org/matlabcentral/answers/85148-differences-calculating-the-sum-of-squares-in-single-between-sum-and-a-loop#comment_165165

Hi - yep just checked on another PC, I get the exactly answer on Matlab 2013a 64bit, but the incorrect answer on 2013a 32bit (Win64)... Deserve to anyone rather repeat this result?

### Community sweetheart Hunt

Find the prizes in MATLAB main and discover how the ar can aid you!

begin Hunting!**An Error Occurred**

Unable to complete the activity because of changes made to the page. Reload the page to see its updated state.

select a internet Site

Choose a internet site to obtain translated contents where easily accessible and see neighborhood events and offers. Based upon your location, us recommend that you select: .

pick net site## How come Get finest Site Performance

Select the China website (in Chinese or English) for finest site performance. Various other princetoneclub.org country sites space not optimized for visits from your location.

See more: Yoga With Adriene Day 11

princetoneclub.org

*Accelerating the pace of engineering and also science*

princetoneclub.org is the leading developer the mathematical computing software for engineers and also scientists.