Can someone point me in the right direction?
n = 1e5;
y_correct = uint64(500010000050000);
I get 500010000050005. I do not know how to go beyond double precision.
function y = cubesLessSquare(n)
% Formula
N = (((sum((1:n).^3)*2 - sum(1:n)^2)*2/n))
% double to char
C = sprintf('%f',N)
% char to vector
Y = C - '0'
% take out the dot and the numbers after the dot
Dot = find(Y<0)
Y([Dot:end]) = []
% join the the numbers
Z = sprintf('%d',Y)
% make to double
y = str2num(Z)
end
% I used Machin's Formula: pi = 4[4arctan(1/5) - arctan(1/239)] because it was used for speed. But it will not go no more than 16 digits. How can I go beyond 16 digits?
function [PI] = pidigit(N,n)
A = 0;
F = 10^300;
% Machin's Formula: pi = 4[4arctan(1/5) - arctan(1/239)]
x1 = 1/5;
x2 = 1/239;
for K = 0:1000000000
A1 = 4*((-1)^K*x1^(2*K+1)/(2*K+1));
A2 = (-1)^K*x2^(2*K+1)/(2*K+1);
A = A + 4*(A1 - A2)*F;
end
E = abs(pi*F-A)/(pi*F);
PI = sprintf('%.f',A) -'0';
sum(PI(1:N-1) == n)
sum(PI(1:N-1) == n)/(N-1)
end
when the code is rewritten as y = [y {s(S:Ind(E))}];, it includes the spaces. But, when the code is rewritten y =[y cellstr(s(S:Ind(E)))] it leaves the spaces out. Why does it do that?