Addition of numbers in array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Muhammad Usman
am 13 Feb. 2021
Kommentiert: Steven Lord
am 16 Feb. 2021
Lets' say I have 2 vectors:
x = [7 4 6];
y = [1 4 4];
But these are not just vector consider them as A number, i.e., 746 and 144. Now I want to add these numbers (as we do on paper, carry method).
so the answer should be 890.
and want display like:
7 4 6
1 4 4
-----
8 9 0
Please help me to code.
Thanks
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 13 Feb. 2021
This is one way
x = [7 4 6];
y = [1 4 4];
z = sscanf(sprintf('%d',x),'%d')+sscanf(sprintf('%d',y),'%d')
4 Kommentare
Steven Lord
am 16 Feb. 2021
Your numbers are too large to guarantee that they can be stored exactly as double precision numbers.
x = 96130549848139976391;
rem(x, 10) % ones digit
spacing = eps(x)
The spacing between consecutive representable numbers in the vicinity of x is 16,384. It is too large even to be stored exactly as a uint64 number.
y = uint64(96130549848139976391) % Saturated at intmax
You will need to store your numbers and perform calculations in arbitrary precision arithmetic, like in Symbolic Math Toolbox.
s = sym('96130549848139976391')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Continuous Waveforms 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!