How writing code sum 1+2+3+4+...+n
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi. How I can writing code in MATLAB sum 1+2+3+4+..+n
and I can change ( n ) to any numbers and MATLAB can sum for me.
Thank you
0 Kommentare
Antworten (2)
Jos (10584)
am 17 Mai 2019
or know your math classics ...
n = 120345428372
s = n*(n+1)/2
% sum(1:n) will fail!
6 Kommentare
Walter Roberson
am 11 Dez. 2023
v = sym('7241511065080263999378')
fprintf('%.999g\n', double(v))
So 7241511065080263868416 is the closest double precision representation of 7241511065080263999378
eps(double(v))
which is large enough adjacent representable double precision numbers in that range are 1048576 apart.
Siehe auch
Kategorien
Mehr zu Number Theory 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!