MATLAB: Sum digits after vpa(N,100)

sum vpa digits

Hi MatLab!
I've stumbled across a problem. I wish to take all the first hundred digits in the square root of 2 —> sqrt(2) and sum them up.
I first use
N=sym('sqrt(2)'); vpa(N,100)
which gives me alot of digits. But when I try to num2str the answer it cant be done. How can I achieve this?

Best Answer

Here you go:
clear all
digits(100);
N=vpa(sym('sqrt(2)'));
sumA = 0;
for i = 1:100
sumA = sumA + (floor(N*(10^(i-1))) - 10*floor(N*10^(i-2)));
end
disp(sumA)
Related Question