What is difference between these two commands?
especially in regards to there application
digital image processingMATLABsignal processing
>> fprintf('%0.20f\n', 1+eps)1.00000000000000022204>> fprintf('%0.20f\n', 1+2.5*eps)1.00000000000000044409
factorial(1:20) < flintmaxans = 1×20 logical array 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
factorial(100)ans = 9.3326e+157
sum(char(factorial(sym(100))) - '0')ans = 648
factdigs = zeros(1,200);factdigs(end) = 1;N = 100;for n = 2:N % multiply. note that you multiply ALL digits of
% the number by n.
factdigs = factdigs * n; % carry op
carry = 1; % a while loop, since there may be multiple carries.
% for example, a multiple carry would occur when you
% multiply the number 6 times 100.
while any(carry) % strip off the units digit
R = rem(factdigs,10); % this divide will always be safe, resulting
% in an exact integer.
carry = (factdigs - R)/10; % The carry is just an add, with a shift.
% if I knew the highest order digit will
% always be zero, I could have used circshift.
factdigs = R + [carry(2:end),0]; endendsum(factdigs)ans = 648
reshape(factdigs,10,20)'ans = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 9 3 3 2 6 2 1 5 4 4 3 9 4 4 1 5 2 6 8 1 6 9 9 2 3 8 8 5 6 2 6 6 7 0 0 4 9 0 7 1 5 9 6 8 2 6 4 3 8 1 6 2 1 4 6 8 5 9 2 9 6 3 8 9 5 2 1 7 5 9 9 9 9 3 2 2 9 9 1 5 6 0 8 9 4 1 4 6 3 9 7 6 1 5 6 5 1 8 2 8 6 2 5 3 6 9 7 9 2 0 8 2 7 2 2 3 7 5 8 2 5 1 1 8 5 2 1 0 9 1 6 8 6 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
factorial(122)ans = 9.875e+202
Best Answer